const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
// expected output: "a"
// expected output: "b"
// expected output: "c"
var fruits = ["apple", "orange", "cherry"];
fruits.forEach(getArrayValues);
function getArrayValues(item, index) {
console.log( index + ":" + item);
}
/*
result:
0:apple
1:orange
2:cherry
*/
var new_array = old_array.map(function(e) {
e.data = e.data.split(',');
return e;
});
$array = array("dog", "rabbit", "horse", "rat", "cat");
$x = 1;
$length = count($array);
foreach($array as $animal){
if($x === 1){
//first item
echo $animal; // output: dog
}else if($x === $length){
echo $animal; // output: cat
}
$x++;
}
theArray.forEach(element => { // ...use `element`... });