Skip to main content

array.filter(function)

Applies a filter function to an array’s items, storing the results in a new array

Availability

Device + Agent

Parameters

Name Type Description
function Function A data-test function

Returns

Array — a new, filtered array

Description

This method applies the supplied test function to every item in the target array one by one. Items which meet the test’s criteria are copied into a new array, created by filter() and returned by it. The new array may or may not be the same size as the target array depending on how many items pass the test.

The passed function must include two parameters: the index value of the item being passed to it, and the item itself. It is the function’s job to make sure the array values passed are relevant for the test it will apply.

Example Code