28 Javascript Array Methods: A Cheat Sheet for Developer
7 min readMar 28, 2022
Let’s understand javascript array functions and how to use them.
Array.map()
Returns a new array with the results of calling a provided function on every element in this array.
const list = [😫, 😫, 😫, 😫];
list.map((⚪️) => 😀); // [😀, 😀, 😀, 😀]// Code
const list = [1, 2, 3, 4];
list.map((el) => el * 2); // [2, 4, 6, 8]
Array.filter()
Returns a new array with all elements that pass the test implemented by the provided function.
const list = [😀, 😫, 😀, 😫];
list.filter((⚪️) => ⚪️ === 😀); // [😀, 😀]// Code
const list = [1, 2, 3, 4];
list.filter((el) => el % 2 === 0); // [2, 4]
Array.reduce()
Reduce the array to a single value. The value returned by the function is stored in an accumulator (result/total).
const list = [😀, 😫, 😀, 😫, 🤪];
list.reduce((⬜️, ⚪️) => ⬜️ + ⚪️); // 😀 + 😫 + 😀 + 😫 + 🤪// OR
const list = [1, 2, 3, 4, 5];
list.reduce((total, item) => total + item, 0); // 15