· 1 min read
JavaScript Array methods Cheat Sheet

Originally from this tweet
[1, 2, 3, 4]
.at(1) // 2
[(1, 2, 3, 4)].pop() // [1, 2, 3]
[(1, 2, 3, 4)].push(5) // [1, 2, 3, 4, 5]
[(1, 2, 3, 4)].fill(1) // [1, 1, 1, 1]
[(1, 2, 3, 4)].join('-') // '1-2-3-4'
[(1, 2, 3, 4)].shift() // [2, 3, 4]
[(1, 2, 3, 4)].reverse() // [4, 3, 2, 1]
[(1, 2, 3, 4)].unshift(1) // [1, 1, 2, 3, 4]
[(1, 2, 3, 4)].includes(2) // true
[(1, 2, 3, 4)].map((num) => num * 2) // [2, 4, 6, 8]
[(l, 2, 3, 4)].some((num) => num > 3) // true
[(l, 2, 3, 4)].find((num) => num > 2) // 3
[(l, 2, 3, 4)].every((num) => num > 3) // false
[(1, 2, 3, 4)].filter((num) => num > 2) // [3, 4]
[(1, 2, 3, 4)].findIndex((num) => num > 2) // 2
[(1, 2, 3, 4)].reduce((acc, num) => acc + num); // 10
// JavaScript Array methods (by @denicmarko)More can be found on Markos blog
Share:


