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.
import {DefineMap} from "can";
const names = [];
const map = new DefineMap({a: "Alice", b: "Bob", e: "Eve"});
map.forEach( (value, propName) => names.push(value) );
console.log( names ); //-> ["Alice", "Bob", "Eve"]
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.
Use
If the callback returns false the loop will stop.
import {DefineMap} from "can";
const names = [];
const map = new DefineMap({a: "Alice", b: "Bob", e: "Eve"});
map.forEach( (value, propName) => {
if (propName === "e") {
return false;
}
names.push(value);
} );
console.log( names ); //-> ["Alice", "Bob"]