JavaScript array.filter() Function

JavaScript Logo

array.filter() – Returns a **new array** containing only the elements for which the callback returns a truthy value.

๐Ÿ‘‰ Syntax

newArray = array.filter((element, index, array) => {
  return /* condition */;
}, thisArg);

๐Ÿงช Example

const nums = [5, 12, 8];
const big = nums.filter(n => n > 10);
console.log(big); // [12]

Comments