Ends in 0d:00h:00m:00s

Buy 1 year, 🎁 Gift 1 year — completely FREE

Split the cost with a friend. You both get 12 months for $99.

Start FREE trial
Background Image

Buy 1 year, Gift 1 year — completely FREE

Start FREE trial
L
last year
Lucacountry asked

How do arrays work?

Kelish Rai
Expert
last year
Kelish Rai answered

Arrays work by storing multiple values in a single variable. Instead of creating a new variable for every value, you can group related values together in an array. This is especially useful when you have a list of items.

Here's a simple example:

const fruits = ["apple", "banana", "orange"];

In this example, fruits is an array that holds three values: apple, banana, and orange.

Here are some things that you can do with arrays:

  • Access values using their index: fruits[0]

  • Update values: fruits[1] = "mango"

  • Add values: fruits.push("grape")

  • Loop through values

Arrays are a basic but powerful tool in programming, and you’ll use them often when working with lists, collections, or structured data.

JS
This question was asked as part of the Learn JavaScript Basics course.