It does exactly what it sounds like: It takes an array, and filters out unwanted elements.
Like map, filter is defined on Array.prototype. It's available on any array, and you pass it a callback as its first argument. filter executes that callback on each element of the array, and spits out a new array containing only the elements for which the callback returned true.
var difficult_tasks = tasks.filter(function (task) {
return task.duration >= 120;
});
Like map, filter is defined on Array.prototype. It's available on any array, and you pass it a callback as its first argument. filter executes that callback on each element of the array, and spits out a new array containing only the elements for which the callback returned true.
var difficult_tasks = tasks.filter(function (task) {
return task.duration >= 120;
});
No comments:
Post a Comment