array methods Flashcards
What is Array.prototype.filter useful for?
It is useful for creating a new array that contains elements that pass a test implemented by a provided function.
ex. const words = [‘spray’, ‘limit’, ‘elite’, exuberant’, ‘destruction’, ‘present’];
const. result = words.filter(word => word.length > 6);
console.log(result);
// expected output: Array [“exuberant”, “destruction”, “present”]
What is Array.prototype.map useful for?
It is useful for creating a new array containing elements with values that are the result of calling a function on the elements of the old (or calling) array.
What is Array.prototype.reduce useful for?
It is useful for when you want to iterate through an array and you need a return value from the previous iteration.
or
It is useful for taking an array and reducing it down to a single value.