map
Map the values in this list to another list.
list.map(callback[, thisArg])
Loops through the values of the list, calling callback
for each one until the list
ends. The return values of callback
are used to populate the returned list.
import {DefineList} from "can";
const todos = new DefineList([
{name: "dishes", complete: false},
{name: "lawn", complete: true}
]);
const names = todos.map((todo) => {
return todo.name;
});
console.log(names.get()); //-> ["dishes","lawn"]
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 (Integer) - the index of the current element of the list.
- list (DefineList) - the
DefineList
the elements are coming from.
The return value of
callback
, includingundefined
values are used to populate the resulting list. - thisArg
{Object}
:The object to use as
this
inside the callback.