filter
Filter a list to a new list of the matched items.
list.filter( callback [,thisArg] )
Filters list
based on the return value of callback
.
var names = new DefineList(["alice","adam","zack","zeffer"]);
var aNames = names.filter(function(name){
return name[0] === "a"
});
aNames //-> DefineList["alice","adam"]
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.
If
callback
returns a truthy result,item
will be added to the result. Otherwise, theitem
will be excluded. - thisArg
{Object}
:What
this
should be in thecallback
.
Returns
A new instance of this DefineList
(may be a subclass), containing the items that passed the filter.
list.filter( props )
Filters items in list
based on the property values in props
.
var todos = new DefineList([
{name: "dishes", complete: false},
{name: "lawn", complete: true}
]);
var complete = todos.filter({complete: true});
complete //-> DefineList[{name: "lawn", complete: true}]
Parameters
- props
{Object}
:An object of key-value properties. Each key and value in
props
must be present on anitem
for theitem
to be in the returned list.