.each javascript code example
Example 1: jquery each
$( "li" ).each(function( index ) {
console.log( index + ": " + $( this ).text() );
});
Example 2: javascript foreach
var colors = ['red', 'blue', 'green'];
colors.forEach(function(color) {
console.log(color);
});
Example 3: for each js
const fruits = ['mango', 'papaya', 'pineapple', 'apple'];
fruits.forEach(function(fruit){
console.log('I want to eat a ' + fruit)
});
Example 4: jquery foreach
$.each( obj, function( key, value ) {
alert( key + ": " + value );
});
Example 5: jquery each
$.each( arr, function( index, value ){
sum += value;
});
$.each( obj, function( key, value ) {
sum += value;
});
Example 6: es6 forEach
const array1 = ['a', 'b', 'c'];
array1.forEach((element) => {
console.log(element)
});