Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn What Are Arrays? | Exploring Arrays
Introduction to JavaScript
course content

Course Content

Introduction to JavaScript

Introduction to JavaScript

1. Getting Started
3. Conditional Statements
4. Mastering Functions
5. Exploring Arrays
6. Discovering Loops

book
What Are Arrays?

Note
Definition

An array is simply an ordered collection of variables.

Defining an Array

The general syntax of defining an array is:

js

We can declare an empty array as well:

python

Arrays are useful when we need to store multiple values in a single variable instead of creating separate variables for each value.

This makes data easier to organize and manipulate. For example, we can store the names of the class students in an array:

We can output all the elements of an array by simply using it's name in a console.log statement:

12345
let students = [ "Emma", "Alex", "Chris" ]; console.log(students); let emptyArray = []; console.log(emptyArray);
copy

Indexing

We can access an element at a specific position in the array by indexing.

The syntax for indexing is:

js

Here arrayName is the name of the array, and index refers to the position of the element in the array.

The index values start from 0, which means the first element always has an index 0.

1234
let students = [ "Emma", "Alex", "Chris" ]; console.log(students[0]); // Output: Emma console.log(students[1]); // Output: Alex console.log(students[2]); // Output: Chris
copy

Using an invalid index returns undefined:

123
let students = [ "Emma", "Alex", "Chris" ]; console.log(students[-1]); // Output: undefined console.log(students[4]); // Output: undefined
copy

1. What is an array in JavaScript?

2. Which of the following is the correct way to declare an array?

3. What does the following code output?

4. What will be the output of the following code?

question mark

What is an array in JavaScript?

Select the correct answer

question mark

Which of the following is the correct way to declare an array?

Select the correct answer

question mark

What does the following code output?

Select the correct answer

question mark

What will be the output of the following code?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 1

Ask AI

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

course content

Course Content

Introduction to JavaScript

Introduction to JavaScript

1. Getting Started
3. Conditional Statements
4. Mastering Functions
5. Exploring Arrays
6. Discovering Loops

book
What Are Arrays?

Note
Definition

An array is simply an ordered collection of variables.

Defining an Array

The general syntax of defining an array is:

js

We can declare an empty array as well:

python

Arrays are useful when we need to store multiple values in a single variable instead of creating separate variables for each value.

This makes data easier to organize and manipulate. For example, we can store the names of the class students in an array:

We can output all the elements of an array by simply using it's name in a console.log statement:

12345
let students = [ "Emma", "Alex", "Chris" ]; console.log(students); let emptyArray = []; console.log(emptyArray);
copy

Indexing

We can access an element at a specific position in the array by indexing.

The syntax for indexing is:

js

Here arrayName is the name of the array, and index refers to the position of the element in the array.

The index values start from 0, which means the first element always has an index 0.

1234
let students = [ "Emma", "Alex", "Chris" ]; console.log(students[0]); // Output: Emma console.log(students[1]); // Output: Alex console.log(students[2]); // Output: Chris
copy

Using an invalid index returns undefined:

123
let students = [ "Emma", "Alex", "Chris" ]; console.log(students[-1]); // Output: undefined console.log(students[4]); // Output: undefined
copy

1. What is an array in JavaScript?

2. Which of the following is the correct way to declare an array?

3. What does the following code output?

4. What will be the output of the following code?

question mark

What is an array in JavaScript?

Select the correct answer

question mark

Which of the following is the correct way to declare an array?

Select the correct answer

question mark

What does the following code output?

Select the correct answer

question mark

What will be the output of the following code?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 1
We're sorry to hear that something went wrong. What happened?
some-alt