JavaScript Arrays
Learn how to store multiple values using arrays, access elements, modify data, and use common array methods.
Reading Time
15 min
Lesson
Lesson 13 of 48
What is an Array?
An array is a special object in JavaScript used to store multiple values in a single variable. Each value is called an element and is accessed using its index, starting from 0.
Creating an Array
Console Output
Click “Run” to see the console output here.
Accessing Array Elements
Array elements are accessed using their index. The first element is at index 0.
Access Elements
Console Output
Click “Run” to see the console output here.
Updating Array Elements
You can change any element by assigning a new value to its index.
Update an Element
Console Output
Click “Run” to see the console output here.
Array Properties
The length property returns the total number of elements present in an array.
Array Length
Console Output
Click “Run” to see the console output here.
Common Array Methods
| Method | Description |
|---|---|
| push() | Adds an element to the end |
| pop() | Removes the last element |
| shift() | Removes the first element |
| unshift() | Adds an element to the beginning |
| includes() | Checks if a value exists |
| indexOf() | Returns the index of an element |
| slice() | Returns a portion of an array |
| splice() | Adds or removes elements |
Using Array Methods
Console Output
Click “Run” to see the console output here.
Remember
Arrays can store different data types including numbers, strings, booleans, objects, functions, and even other arrays.