forEach
Call a function for each element of a DefineList.
list.forEach(callback[, thisArg])
Loops through the values of the list, calling callback
for each one until the list ends
or false
is returned.
list.forEach(function(item, index, list){ ... })
Parameters
- callback
{function(item, index, list)}
:A function to call with each element of the DefineList. The three parameters that callback gets passed are:
- item - the element at index.
- index - the current element of the list.
- list - the DefineList the elements are coming from.
If the callback returns
false
the looping stops. - thisArg
{Object}
:The object to use as
this
inside the callback.
Use
forEach
calls a callback for each element in the DefineList.
var list = new DefineList([1, 2, 3]);
list.forEach(function(element, index, list) {
list.get(index, element * element);
});
list.get(); // [1, 4, 9]