each(collection: Array, context: Object, callback: function);
collection. Items array.
context. Function context.
callback. Callback function.
The each method iterates through a specified array of items executing the function at each iteration.
To execute the example, add a link to PP.js scenario file to HTML page. Determine an array of integers, next increase each array item by one:
// Determine an integer array
var elements = [5, 9, 6, 7, 2];
console.log("Source array of elements: [" + elements + "]");
// Determine callback function
var callback = function (index, element) {
element++;
elements[index] = element;
};
if (PP.isFunction(callback)) {
// Increase each array element by one
PP.each(elements, this, callback);
console.log("New array of elements: [" + elements + "]");
} else {
console.log("Array element processing function is not determined");
};
After executing the example integer array items are shown increased by one:
Initial array of elements: [5,9,6,7,2]
New array of items: [6,10,7,8,3]
See also: