Zero index
The first item is array[0].
Arrays store ordered lists of values. They are the foundation for lists, queues, search results, UI rows and data transformations.
const topics = ["HTML", "CSS", "JavaScript"]; console.log(topics[0]); console.log(topics.length);
Arrays & Collections
Arrays are used when order matters or when you have many values of the same kind. A list of records, tags, messages or selected ids is usually an array.
Array positions start at zero. The first item is index 0, the second item is index 1, and length tells you how many items are in the array.
Arrays are objects and they are mutable by default. Some methods change the original array, while others return a new array. Knowing the difference is essential.
The first item is array[0].
The number of items in the array.
Many array methods can change the original array.
Arrays work with for...of, spread and many collection patterns.
Examples
const topics = ["HTML", "CSS", "JavaScript"]; const firstTopic = topics[0]; const totalTopics = topics.length;
const topic1 = "HTML"; const topic2 = "CSS"; const topic3 = "JavaScript"; // This becomes hard to loop, filter or render.
Code patterns
These are the patterns developers search for constantly: reading items, copying arrays, choosing map/filter/reduce, sorting with a comparator, destructuring and using Set or Map.
Use an array literal for most lists.
const topics = ["HTML", "CSS", "JavaScript"];
Use square brackets to read a position.
const topics = ["HTML", "CSS", "JavaScript"]; console.log(topics[0]);
Spread creates a new array with extra items.
const topics = ["HTML", "CSS"]; const nextTopics = [...topics, "JavaScript"];
Use Array.isArray instead of typeof.
const value = ["HTML", "CSS"]; console.log(Array.isArray(value));
Rules that matter
Arrays and collections are not just storage. They describe whether the code is selecting, transforming, grouping, counting, sorting or enforcing uniqueness.
If position or sequence matters, an array is a natural fit.
The first item is index 0.
length is one more than the last index.
push changes the original array; map returns a new one.
typeof [] returns object, not array.
Arrays are easier to work with when items have the same shape.
Production thinking
Most UI data eventually becomes a list. Arrays are how JavaScript stores and transforms those lists.
Arrays often render navigation, cards or messages. Stable order and clear item data help accessible output stay predictable.
Production code should avoid accidental array mutation when the same data is shared across modules or UI state.
Arrays often hold rendered links, headings or structured content blocks. Stable arrays produce stable page output.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
A collection method should tell the reader what kind of operation is happening before they read the callback body.