array methods Flashcards

1
Q

What is Array.prototype.filter useful for?

A

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”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Array.prototype.map useful for?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Array.prototype.reduce useful for?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly