javascript for each value in array code example
Example 1: js for each item in array
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
Example 2: javascript foreach
let numbers = ['one', 'two', 'three', 'four'];
numbers.forEach((num) => {
console.log(num);
});
Example 3: for each array javascript
var fruits = ["apple", "orange", "cherry"];
fruits.forEach(getArrayValues);
function getArrayValues(item, index) {
console.log( index + ":" + item);
}
Example 4: javascript foreach
const colors = ['blue', 'green', 'white'];
function iterate(item) {
console.log(item);
}
colors.forEach(iterate);