A Practical Cheat Sheet for JavaScript Array Methods

Modern JavaScript’s array methods replace most manual for-loops with clearer, more declarative code — worth knowing the full set well enough to reach for them automatically.

const nums = [5, 3, 8, 1, 9];

nums.map(n => n * 2);                  // [10, 6, 16, 2, 18]
nums.filter(n => n > 4);               // [5, 8, 9]
nums.reduce((sum, n) => sum + n, 0);   // 26
nums.find(n => n > 4);                 // 5 (first match)
nums.findIndex(n => n > 4);            // 0
nums.some(n => n > 8);                 // true
nums.every(n => n > 0);                // true
nums.sort((a, b) => a - b);            // [1, 3, 5, 8, 9] - mutates in place!

const users = [{name: 'Alice', age: 30}, {name: 'Bob', age: 25}];
users.flatMap(u => u.name.split(''));  // flatten a mapped array of arrays

sort() mutates the original array in place — a common source of bugs when you expect a new array back. Use [...nums].sort(...) or the newer toSorted() if you need to preserve the original order elsewhere.