Skip to content

­ Transformation Methods

Creates a new array by transforming each element.

const nums = [1, 2, 3];
const doubled = nums.map(n => n * 2);
// [2, 4, 6]

Time: O(n) Mutates original? No


Returns elements that match a condition.

const nums = [1, 2, 3, 4];
const evens = nums.filter(n => n % 2 === 0);
// [2, 4]

Time: O(n) Mutates original? No


Reduces array to a single value.

const nums = [1, 2, 3, 4];
const sum = nums.reduce((acc, n) => acc + n, 0);
// 10

Time: O(n) Mutates original? No