forEach
Call a function on each property of a DefineMap.
map.forEach( callback(value, propName ) )
forEach
iterates through the map instance, calling a function
for each property value and key.
map.forEach(function(value, propName){ ... });
Parameters
- callback
{function(value, propName)}
:The function to call for each property The value and key of each property will be passed as the first and second arguments, respectively, to the callback. If the callback returns
false
, the loop will stop.
Use
Example
var names = [];
new DefineMap({a: 'Alice', b: 'Bob', e: 'Eve'}).forEach(function(value, key) {
names.push(value);
});
names; // ['Alice', 'Bob', 'Eve']
names = [];
new DefineMap({a: 'Alice', b: 'Bob', e: 'Eve'}).forEach(function(value, key) {
names.push(value);
if(key === 'b') {
return false;
}
});
names; // ['Alice', 'Bob']