We have learned about Number, strings and Boolean data types. These are great to store individual amount of data.  Sometimes we need to manipulate a group of data like a set of fruits, a list of ingredients to make a yummy recipe.  We can create as many variables as we can but it would be good to go with array to handle a series or a set of data.

We can declare an array in JavaScript with array markers which are opening and closing square brackets.

var breakFast= [];

The variable breakFast is now an array.

Each segment in an array is called an Element. Every element has an index which is use to reference that element. Index number starts from ‘0’

Let’s assign some values in breakFast array:

breakFast [0] = “BREAD”;

breakFast [1] = “EGGS”;

breakFast [2] = “TEA”;



We can access any element of an array by its index number, in above example if we want to access EGGS we can simple call element with index number 1


We can also assign the values to the array when we are declaring it:

var webDesign =[“HTML”, “CSS”, “JS”];



We can also create an array of arrays which we call a multi-dimensional array.

var morning= [breakFast,webDesign];


Lets try to print breakfast Array in alert function

Alert(morning[breakFast]);// it will display BREAD,EGGS,TEA

Alert(morning[0]); // it will also display all the elements of breakfast array

What if we want to just access the second element of the breakFast array from morning array?



The above image might help you to understand how we can handle multi-dimensional array.

Alert(morning[0][1]); // it will display EGGS

That’s very much it for this toast. I hope you enjoy it, Fell free to comment your feedback. Take care