r/angular • u/zeptobook • Dec 30 '18
Eleven Ways To Learn Javascript Array Iteration Effectively - ZeptoBook
https://www.zeptobook.com/eleven-ways-to-learn-javascript-array-iteration-effectively/
3
Upvotes
1
u/sidi9 Jan 04 '19
Doesn't mention that a for loop is faster than any of them which important when iterating over sets of thousands of items.
8
u/kescusay Dec 30 '18
TL;DR: It's just an overview of these array functions:
Array.map() - Make new arrays from old!
Array.filter() - Get rid of something you don't want in the array!
Array.forEach() - Do something with everything in the array!
Array.reduce() - Make a new something-that-isn't-an-array from an array!
Array.reduceRight() - Make a new something-that-isn't-an-array from an array, backwards!
Array.some() - Check if at least one member of an array matches a condition!
Array.every() - Check if all members of an array match a condition!
Array.find() - Find the thing!
Array.findIndex() - Find the spot where the thing you're looking for is!
Array.indexOf() - Also find the spot where the thing you're looking for is!
Array.lastIndexOf() - Find the spot where the last of the things you're looking for is!
There you go.