Skip to main content

What are arrays?

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.
JavaScript arrays are Python lists. Same square bracket syntax, same zero-based indexing, same idea.

Accessing items

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.

Getting the last item

.at() supports negative indices just like Python. Use .at(-1) to get the last item instead of the awkward arr[arr.length - 1].

Array length

Note: .length is a property, not a method. No parentheses needed.

Modifying arrays

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.

Checking if something is in an array

JavaScript uses .includes() where Python uses in. Both check for existence.

Slicing arrays

.slice() returns a new array without modifying the original. Same behavior as Python’s list[1:3], just with method syntax instead of bracket notation.

What’s next?

You can create and access arrays. Now let’s learn the methods that make arrays truly powerful — .map(), .filter(), .find(), and more.

Array methods

Transform, filter, and search arrays