# Arrays in JavaScript: Storing Multiple Values Easily

Imagine you want to store a list of your **favorite movies** in JavaScript.

You could do something like this:

```plaintext
let movie1 = "Inception";
let movie2 = "Interstellar";
let movie3 = "The Dark Knight";
```

But this quickly becomes messy if the list grows.

That’s where **arrays** help.

* * *

## What arrays are and why we need them

An **array** is a collection of values stored in a single variable.

Instead of creating many variables, you can store everything in one place.

Example idea:

*   list of fruits
    
*   student marks
    
*   tasks in a todo app
    

Arrays keep these values **organized and easy to access**.

* * *

## How to create an array

In JavaScript, arrays are created using square brackets `[]`.

Example:

```plaintext
let fruits = ["Apple", "Banana", "Mango"];
```

Now the variable `fruits` holds three values together.

* * *

## Accessing elements using index

Each item in an array has a **position number called an index**.

Important: **index starts from 0**.

Example:

```plaintext
let fruits = ["Apple", "Banana", "Mango"];

console.log(fruits[0]); // Apple
console.log(fruits[1]); // Banana
```

So the first item is always index **0**, not 1.

* * *

## Updating elements

You can also **change values** in an array using the index.

Example:

```plaintext
let fruits = ["Apple", "Banana", "Mango"];

fruits[1] = "Orange";

console.log(fruits);
```

Now `"Banana"` becomes `"Orange"`.

* * *

## Array length property

Arrays have a property called **length**.

It tells how many elements are inside the array.

Example:

```plaintext
let fruits = ["Apple", "Banana", "Mango"];

console.log(fruits.length);
```

Output will be `3`.

* * *

## Basic looping over arrays

Often we want to go through every item in an array.

A simple way is using a **for loop**.

Example:

```plaintext
let fruits = ["Apple", "Banana", "Mango"];

for (let i = 0; i < fruits.length; i++) {
  console.log(fruits[i]);
}
```

This prints each fruit one by one.

* * *

## Small practice exercise

Try this simple exercise.

Create an array of **5 favorite movies**.

Example:

```plaintext
let movies = ["Inception", "Interstellar", "Avatar", "Titanic", "Joker"];
```

Now try:

1.  Print the **first movie**
    
2.  Print the **last movie**
    
3.  Change one value in the array
    
4.  Loop through the array and print all movies
    

Practicing small examples like this makes arrays feel natural.
