JavaScript Arrays: Tutorial & Quiz

What is an Array?

An array is a special variable in JavaScript that can hold multiple values in a single variable. You can think of an array as a list of values.

Creating an Array

You can create an array by enclosing values in square brackets (`[]`), separated by commas.

let fruits = ['apple', 'banana', 'cherry'];

Accessing Array Elements

You can access the elements in an array by using an index. The index starts from 0.

console.log(fruits[0]); // Output: apple

Common Array Methods

Interactive Example

Click the button to add a fruit to the list:

Quiz: Test Your Knowledge

1. Which method adds an element to the end of an array?





2. Which method removes the first element of an array?





3. How do you access the first element of an array called `fruits`?