.forEach( array, handler_function )
Iterates over the array elements and pass the element as input parameter to the handler function. If the handler function returns a value, that will overwrite the initial value and will be returned as new Array.
Parameters
Returns
Example 1
JS
Example 2
$.domLoaded(function() { var arr = [1,2,3,4]; // Handler function add 5 to each element and returns var newArr = $.Util.forEach( arr , function(el) { return el + 5; }); console.log(newArr); // will print [6,7,8,9] });
JS
$.domLoaded(function() { var names = [ {name : "Senthil", age : "26"} , {name : "Ganesh", age : "29" }, {name : "Shane", age : "26" }]; console.log(" Name | Age "); // Handler function prints the names and age $.Util.forEach( names , function(el) { console.log(el.name + " | " + el.age); }); });
Result
Name | Age Senthil | 26 Ganesh | 29 Shane | 26 | ||||||||||||||||||||