jPaq Docs - Array.prototype.filter()

Quick Stats

Target Platforms:  PC (JScript) and the web (JavaScript)
Download Count:  747


Creates a new array with all of the elements of this array for which the provided filtering function returns true.


  1. fn => Function
    The filtering function that will be called for all of the elements within the array. The first parameter is the element that will be checked against this function. The second parameter is the index of the element. The third parameter is a reference to this array. To keep the specified element in the filtered array, a value which evaulates to true must be returned.
  2. [objThis] => Object
    Optional. The object to which the "this" keyword will refer for each invocation of the filtering function. If this is not specified, "this" will refer to the global object of the filtering function.


Returns a new array of the filtered items.

Related Examples

  1. Compacting Arrays
    The JavaScript library Prototype offers a function which basically removes all of the undefined and null values from the array. Fortunately, JavaScript 1.6 offers…