LibraryJavaScriptArrays

Arrays

Store ordered values and transform them with map, filter, find, and reduce.

Updated Tested with ECMAScript 2026

Arrays hold ordered collections. JavaScript provides methods for reading, searching, transforming, and combining them without manually managing every index.

Read and update

courses.js
const courses = ["HTML", "CSS", "JavaScript"];
console.log(courses[0]);
console.log(courses.at(-1));

courses.push("TypeScript");
const nextCourse = courses.shift();

push, pop, shift, unshift, splice, sort, and reverse mutate an array. Mutation can be appropriate locally, but immutable transformations are easier to reason about across an application.

Transform and select

progress.js
const lessons = [
  { title: "HTML", complete: true },
  { title: "CSS", complete: false },
  { title: "JavaScript", complete: false },
];

const titles = lessons.map((lesson) => lesson.title);
const unfinished = lessons.filter((lesson) => !lesson.complete);
const current = lessons.find((lesson) => !lesson.complete);

These methods return new arrays or values and leave the source array unchanged.

Summarize values

minutes.js
const minutes = [8, 12, 10];
const total = minutes.reduce((sum, value) => sum + value, 0);

Use some to ask if any item matches and every to ask if all do. Prefer the method that names your intent over a generic reduce.

Keep this

Use arrays for ordered collections, learn which methods mutate, and favor expressive transformations for derived data.

Your place is saved on this device.