filter()

Creates a new object or a new array based on the specified object array. This new array will only have the values which pass the test function.

This function is valid in v2.21.0 to v2.22.1. This function has been downloaded 7 times.

Parameters

{Array|Object} arrOrObj
Array (or array-like object) or object which will be duplicated with only the values that pass the test function.
{Function} test
Function that will be called for every value in arrOrObj and whose return value for each call will be coerced to a boolean and used to determine if the value will be kept in the resulting array or object returned by filter(). Only return values that are true-ish will be kept. The first argument passed will be the value that is being tested. The second argument passed will be the index or key of the value that is being tested. The third argument passed will be arrOrObj. The this keyword will reference opt_this.
{*=} opt_this Optional, Default:global
If not given or undefined or null, the global object will be used. If given as a primitive, the object version of the value will be used. This object will be used as this within test().

Returns

{Array|Object}
If arrOrObj is an array (or an array-like object) then an array with the filtered values will be returned. Otherwise an object with the filtered values will be returned.

Required Functions

This function directly requires the following functions which are included automatically:

  • has()
    Every object descended from Object inherits the hasOwnProperty method. This method can be used to determine whether an object has the specified property as a direct property of that object; unlike the in operator, this method does not check down the object's prototype chain.
  • isArrayLike()
    Determines if an object is an array or at least array-like.

Requiring Function

This function is directly required by the following function:

  • compact()
    Create a new array or object with all of the false-ish values removed.