Arrays — map, filter, reduce and the Rest — Concept Check
Questions on Arrays — map, filter, reduce and the Rest. The array methods are how JavaScript expresses data transformation. Knowing which ones mutate and which return a new array is more important than knowing all of them.
Questions in this quiz
8 questions on Arrays — map, filter, reduce and the Rest — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You have an array of numbers and need to double each value. Which method should you use?
- Areduce
- Bmap
- Csort
- Dfilter
2.A developer uses the sort method on an array of numbers without a compare function, expecting it to sort numerically. What will happen?
- AIt will sort numerically by default
- BIt will return a new sorted array
- CIt will sort as strings by default
- DIt will throw an error
3.Which method would you use to remove the first element of an array and return it?
- Aslice
- Bshift
- Cunshift
- Dsplice
4.Given an array of objects, how can you find the first object with a specific property value?
- Areduce
- Bfilter
- Cmap
- Dfind
5.A React component fails to re-render after an array is modified. What could be the issue?
- AThe array was reassigned
- BThe array was filtered
- CThe component lacks a key
- DThe array was mutated directly
6.To sum all values in an array, which method is most appropriate?
- Areduce
- Bconcat
- Cmap
- Dfilter
7.Which method will return a new array containing only elements that meet a specific condition?
- Asplice
- Bmap
- Creduce
- Dfilter
8.What is the result of calling flat on a nested array with a depth of 1?
- AIt flattens all levels
- BIt returns the same array
- CIt throws an error
- DIt flattens one level of nesting