const arr = ["a", "b", "c"];

arr.forEach(function(element) {
    console.log(element);
});
// Output:
// "a"
// "b"
// "c"
arr.forEach(function(currentValue[, index[, array]]) {
    // code to execute
}[, thisArg]);
// Arrow function with only current value:
forEach((element) => { /* … */ })

// Arrow function with current value and index:
forEach((element[, index]) => { /* … */ })

// Arrow function with current value, index, and original array:
forEach((element[, index[, array]]) => { /* … */ })

// Using a named callback function:
forEach(callbackFn)
forEach(callbackFn[, thisArg])

// Inline anonymous function:
forEach(function (element) { /* … */ })
forEach(function (element[, index]) { /* … */ })
forEach(function (element[, index[, array]]) { /* … */ })
forEach(function (element[, index[, array]]) { /* … */ }[, thisArg])
const numbers = [1, 2, 3, 4, 5];

const result = numbers.forEach(function(number) {
    return number * 2; // Even if a value is returned, forEach() still returns undefined
});

console.log(result); // Output: undefined
const numbers = [1, 2, 3, 4, 5];

numbers.forEach(function(number) {
    console.log(number);
}); // Output: 1 2 3 4 5
const numbers = [1, 2, 3, 4, 5];
let sum = 0;

numbers.forEach(function(number) {
    sum += number;
});

console.log(sum); // Output: 15
const numbers = [10, 25, 30, 45];

let foundNumber = null;

numbers.forEach(function(number) {
    if (number > 30) {
        foundNumber = number;
    }
});

console.log(foundNumber); // Output: 45
const names = ['Alice', 'Bob', 'Charlie'];
const greetings = [];

names.forEach(function(name) {
    greetings.push(`Hello, ${name}!`);
});

console.log(greetings); // Output: ['Hello, Alice!', 'Hello, Bob!', 'Hello, Charlie!']
const people = [
    {name: 'Alice', age: 30},
    {name: 'Bob', age: 25},
    {name: 'Charlie', age: 35}
];

people.forEach(function(person) {
    person.age += 5;
});

console.log(people);
/* Output:
    [
        {name: 'Alice', age: 35},
        {name: 'Bob', age: 30},
        {name: 'Charlie', age: 40}
    ]
*/
const numbers = [1, 2, 3, 4];
let foundNumber = null;

for (let i = 0; i < numbers.length; i++) {
    if (numbers[i] > 3) {
        foundNumber = numbers[i];
        break;
    }
}

console.log(foundNumber); // Output: 4
const numbers = [1, 2, 3, 4, 5];

const doubledNumbers = numbers.map(function(number) {
    return number * 2;
});

console.log(doubledNumbers); // Output: [2, 4, 6, 8, 10]
// Original array
const numbers = [1, 2, 3, 4, 5];

// Using forEach()
const squaredNumbersForEach = [];

numbers.forEach(function(number) {
    squaredNumbersForEach.push(number * number);
});

console.log("Using forEach():", squaredNumbersForEach);
// Output: "Using forEach():" [1, 4, 9, 16, 25]

// Using map()
const squaredNumbersMap = numbers.map(function(number) {
    return number * number;
});

console.log("Using map():", squaredNumbersMap);
// Output: "Using map():" [1, 4, 9, 16, 25]