Skip to content

Chapter 8 of 33

Arrays

Transform, search, reduce, iterate, copy, and model nested array data.

42 minutes 10 quick checksBy Subha Prasad
Lesson 8 of 33Course navigation

Lesson content

Read, practise, then check your understanding

Arrays are resizable indexed objects. They can hold mixed values, though consistent element shapes make code safer and engines easier to optimize.

Declarative operations

const scores = [72, 84, 91, 68];
const passing = scores.filter(score => score >= 80);
const curved = scores.map(score => Math.min(100, score + 5));
const total = scores.reduce((sum, score) => sum + score, 0);

find returns an element, findIndex its index, some/every test conditions, and includes checks membership. Mutators include push, pop, splice, sort, and reverse; modern toSorted, toReversed, and toSpliced return copies. Spread and slice are shallow. Multidimensional arrays are nested arrays and may be ragged. Avoid sparse arrays and supply numeric comparators to sort.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes Array?
Which JavaScript term matches this description: An indexed resizable object whose length tracks the highest indices.
Which statement best describes map?
Which JavaScript term matches this description: A non-mutating transformation returning one result element per input element.
Which statement best describes filter?
Which JavaScript term matches this description: A non-mutating selection returning elements whose predicate passes.
Which statement best describes reduce?
Which JavaScript term matches this description: A fold combining elements into one accumulated result.
Which statement best describes sparse array?
Which JavaScript term matches this description: An array with missing indices rather than explicit undefined values.

0 of 10 checks passed

Your progress is saved on this device.

Arrays | JavaScript Lesson | Subha Prasad