Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

filter

The filter() method of the Array object returns a new array containing only the elements that pass the evaluation provided in the callback function.

Syntaxarray.filter( callback )

Parameters

callback Reference a callback function that will test each element in the array. element - represents each element of the array individually as they pass through the callback. index - indicates the index number of the element passing through the callback. array - a reference to the array object calling the every() method.

Examples

Return new array containing numbers under 30. function test( element, index, array ) { return element < 30; } var array = [ 23,52,12,84,10,47 ]; alert( array.filter(test) ); /* 23,12,10 */

JavaScript

Methods

addEventListeneralertaveragebackblurconcatcreatedecodeURIdecodeURIComponentencodeURIencodeURIComponentevaleveryfilterforwardgoisArrayisFiniteisNaNjoinparseFloatparseIntpoppushpushStatereducereplaceStatereverseshiftshuffleslicesomesortspliceunshiftwrite