We need a way to store a lot of data into a single variable, much like a Toto ticket showing 7 numbers at a go.

In this module, you will learn about arrays, how they work, when and how to use them.


Lesson 1 of 6: What are arrays?

Arrays

An array is used to store a group of elements of the same type. View the video below to understand why and how an array is used.

Arrays.mp4


Lesson 2 of 6: Accessing and updating array

Accessing Array.png

Accessing array

Arrays are indexed starting at zero. Every element of the array has a corresponding index. Thus, friendsArray[1] would give "Brenda" and friendsArray[3] would give "Danny".


Creating and initializing a new array

There are 2 ways to create a new array.

var friends = [];

var friends = new Array();

Size of an array

In the code below,

marks = [80, 70, 60, 65, 50];

marks.length would give the size of the array