javascript each element in array code example
Example 1: for each array javascript
var fruits = ["apple", "orange", "cherry"];
fruits.forEach(getArrayValues);
function getArrayValues(item, index) {
console.log( index + ":" + item);
}
/*
result:
0:apple
1:orange
2:cherry
*/
Example 2: perform a function on each element of array javascript
var new_array = old_array.map(function(e) {
e.data = e.data.split(',');
return e;
});