map, filter and reduce
map returns a new array with each item transformed. filter keeps the items that pass a test. reduce folds the whole array into one value. find returns the first match and some or every test the whole list.
These methods do not change the original array, and they chain nicely.
Example
const prices = [1200, 450, 3000, 800];
const withTax = prices.map((p) => p * 1.075);
console.log(withTax);
const big = prices.filter((p) => p >= 1000);
console.log(big);
const total = prices.reduce((sum, p) => sum + p, 0);
console.log(total);
console.log(prices.find((p) => p < 500));
console.log(prices.some((p) => p > 2000), prices.every((p) => p > 500));Exercise
Keep only the items that pass the test.
nums.((n) => n > 2)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.