Standard built-ins

Array.prototype.filter()

Try the free JavaScript compiler

Collects present elements whose callback result is truthy, in original relative order. Ordinary holes are skipped and selected object values remain shared.

Formal Syntax & Structure

javascript syntaxjavascript
array.filter(callback, thisArg?)

Parameters & Attributes

NameTypeDescription
callbackfunctionTests each present value with value, index, source.
thisArganyOptional this value for ordinary callback functions.

Return Value

Array

Dense array of qualifying elements for an ordinary receiver.

Working Example

Example Snippetjavascript
console.log([1,4,6].filter(n=>n>3).join(","));
JavaScript Reference