Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Understanding Arrays | Mastering Arrays
JavaScript Data Structures

Understanding ArraysUnderstanding Arrays

Arrays are versatile data structures used to store and manipulate collections of values. They are commonly used for managing lists of some items. Here, we will explore the creation of arrays and how to access their elements.

Creating Arrays

We can create an array using square brackets [], known as array literals. Commas should separate elements within the array.

Here, the sport array contains three elements: "basketball", "hockey", and "cricket".

Accessing Array Elements

We can access specific elements within an array by using square brackets with the element's index. Array indices start at 0, meaning the first element has an index of 0, the second element has an index of 1, and so on.

In this example, we access the elements of the motorcycleBrands array using their indices.

  • The first element is accessed with motorcycleBrands[0];
  • The second with motorcycleBrands[1];
  • The third with motorcycleBrands[2];
  • The forth with motorcycleBrands[3].
1. How do we create an array in JavaScript?
2. Which of the following statements correctly defines an array with three elements: "apple," "banana," and "cherry"?
3. What is the index of the first element in an array?
4. In the example below, how can we access the second element (`"Laptop"`) of the `products` array?
5. What will be the output in the code below?

How do we create an array in JavaScript?

Select the correct answer

Which of the following statements correctly defines an array with three elements: "apple," "banana," and "cherry"?

Select the correct answer

What is the index of the first element in an array?

Select the correct answer

In the example below, how can we access the second element ("Laptop") of the products array?

Select the correct answer

What will be the output in the code below?

Select the correct answer

Everything was clear?

Section 4. Chapter 1
course content

Course Content

JavaScript Data Structures

Understanding ArraysUnderstanding Arrays

Arrays are versatile data structures used to store and manipulate collections of values. They are commonly used for managing lists of some items. Here, we will explore the creation of arrays and how to access their elements.

Creating Arrays

We can create an array using square brackets [], known as array literals. Commas should separate elements within the array.

Here, the sport array contains three elements: "basketball", "hockey", and "cricket".

Accessing Array Elements

We can access specific elements within an array by using square brackets with the element's index. Array indices start at 0, meaning the first element has an index of 0, the second element has an index of 1, and so on.

In this example, we access the elements of the motorcycleBrands array using their indices.

  • The first element is accessed with motorcycleBrands[0];
  • The second with motorcycleBrands[1];
  • The third with motorcycleBrands[2];
  • The forth with motorcycleBrands[3].
1. How do we create an array in JavaScript?
2. Which of the following statements correctly defines an array with three elements: "apple," "banana," and "cherry"?
3. What is the index of the first element in an array?
4. In the example below, how can we access the second element (`"Laptop"`) of the `products` array?
5. What will be the output in the code below?

How do we create an array in JavaScript?

Select the correct answer

Which of the following statements correctly defines an array with three elements: "apple," "banana," and "cherry"?

Select the correct answer

What is the index of the first element in an array?

Select the correct answer

In the example below, how can we access the second element ("Laptop") of the products array?

Select the correct answer

What will be the output in the code below?

Select the correct answer

Everything was clear?

Section 4. Chapter 1
some-alt