Array Iterators Flashcards
(13 cards)
Returns an iterator that contains key/value pairs of each index in the array
array.entries()
Tests whether all elements in the array pass the test implemented by the provided function
array.every()
Creates a new array with all elements that pass the test implemented by the provided function.
array.filter() (immutable - creates a new array)
Returns the first element in an array that satisfies the provided testing function.
array.find()
Return the index of the first element in an array that satisfies the provided testing function.
array.findIndex()
Iterates the array in reverse order and returns the value of the first element that satisfies the provided testing function.
array.findLast()
Iterates the array in reverse order and returns the index of the first element that satisfies the provided testing function.
array.findLastIndex()
Apply callback and flatten results 1 level
array.flatMap()
const arr1 = [1, 2, 1];
const result = arr1.flatMap((num) => (num === 2 ? [2, 2] : 1));
// Expected output: Array [1, 2, 2, 1]
Execute a provided function once for each array element.
array.forEach()
When you want to transform elements in an array.
array.map()
When you want derive a single value from multiple elements in an array.
array.reduce()
Derive a single value from multiple elements in an array from right to left.
array.reduceRight()
Test that at least one element of the array passes the test implemented by the given function
array.some()