The filter()
function will return a new list of the items in the original list that match the condition.
filter(list, condition)
list.filter(condition)
Code language: JavaScript (javascript)
Keep in mind that filter()
doesn’t modify the original list. It simply creates a new list that contains only the items from the original that pass the test.
Example Formulas
[1, 2, -3, 0, 5].filter(
current > 0
)
/* Output: [1, 2, 5] */
Code language: JavaScript (javascript)
Get the number of tasks in a project with a weekend due date:
prop("Tasks").filter(
current.prop("Due").day() > 5
).length()
/* Sample Output: 2 */
Code language: JavaScript (javascript)