Arrays store multiple values in a single variable. You’ll use them constantly — lists of users, product catalogs, API responses, form options, navigation items. Any time you have a collection of things, that’s an array.
Accessing an index that doesn’t exist returns undefined instead of throwing an error. This is different from Python, which raises an IndexError. It can lead to silent bugs if you’re not careful.
const colors = ["red", "green", "blue"];// Add to the endcolors.push("yellow");console.log(colors); // ["red", "green", "blue", "yellow"]// Remove from the endconst last = colors.pop();console.log(last); // "yellow"console.log(colors); // ["red", "green", "blue"]// Add to the beginningcolors.unshift("white");console.log(colors); // ["white", "red", "green", "blue"]// Remove from the beginningconst first = colors.shift();console.log(first); // "white"console.log(colors); // ["red", "green", "blue"]
Method
What it does
Returns
.push(item)
Add to end
New length
.pop()
Remove from end
Removed item
.unshift(item)
Add to beginning
New length
.shift()
Remove from beginning
Removed item
These methods mutate the original array. In React, you’ll avoid them and use non-mutating patterns instead (spread operator, .filter(), .map()). More on that when you learn React state.