12 JavaScript array methods, one loop 🦉
#javascript #coding #learntocode
12 JavaScript array methods, one loop 🦉
1. map: transforms every item
2. filter: keeps what passes the test
3. reduce: boils it down to one value
4. find: first match (or undefined)
5. findIndex: index of the first match
6. some: is at least one true?
7. every: are all of them true?
8. includes: is the value in there?
9. flat: unnests one level
10. sort: sorts as TEXT by default ⚠️
11. slice: copies a part, original kept
12. at: counts back from the end
Gotcha: [10, 1, 5].sort() gives [1, 10, 5].
Fix it with .sort((a, b) => a - b) to get [1, 5, 10].
Which one do you use the most? Drop the number 👇
Save this for your next interview 📌
#javascript #coding #learntocode #webdevelopment #100daysofcode
Comments
Comments from the original post on Instagram
No comments yet
