Arrays in JavaScript
Arrays = how to keep many values in one list and work with them.
This chapter has 2 lessons and 10 exercises you run and check in your browser. Plan on about 50 minutes.
- Array Fundamentals: creating arrays, adding and removing items, copying and combining.
- Array Operations:
map,filter,reduce, searching, sorting and grouping.
After this chapter, you can:
- Create a list and read any item by its position.
- Add, remove and replace items, with or without changing the original.
- Transform, filter and total a list in one line each.
- Sort, search and group a list of orders or products.
Every lesson has short explanations, code boxes you edit and run in the live editor, and a web page example you can click.
Before you start, finish Dates and Times.
Next chapter: Objects.
Lessons in this section
- Array Fundamentals
Creating arrays and reading items by index, push, pop, unshift and shift, slice versus splice, copying with spread, changing a list without changing the original with map, filter, with and toSpliced, combining with concat, and flattening with flat and flatMap.
- Create an array and read elements by index and with at()
- Add and remove items with push, pop, unshift and shift
- Tell slice, which copies, apart from splice, which changes the array
- Copy an array and update one element without changing the original
- Array Operations
Transforming arrays with forEach, map, filter, reduce and flatMap, searching with find, findIndex, includes, indexOf, some and every, sorting numbers, text and objects with comparators, toSorted and toReversed, and grouping with Object.groupBy and Map.groupBy to count, total, average and rank.
- Transform arrays with forEach, map, filter, reduce and flatMap
- Search arrays with find, findIndex, includes, indexOf, some and every
- Write comparators that sort numbers, text and objects correctly
- Choose toSorted and toReversed over sort and reverse to keep the original