Table of Contents
Back Button
Back to Chapter
Control Statements
No items found.
Function & Events
No items found.
Array and its Types
No items found.
OOP : Object Oriented Programming
No items found.
Javascript Standards
No items found.
HTML DOM
No items found.
Javascript : Advanced 1
No items found.
Javascript : Advanced 2
No items found.
Additional JavaScript
No items found.

Multi - Dimensional Array

Introduction

Multidimensional array is an array, which contains one or more arrays.

Multi-Dimensional Array Declaration

Syntax

var arrayName = [['value','value',...],['value','value',...],['value','value',...],....];

We can declare 2-Dimenesional, 3-Dimensional and any No. of Dimensional array.

Example

We are Creating a Array, Which stores the Name, Age and Gender of 3 peoples.

var identity = [['Sam','25','Male'],['Jatin','19','Male'],['Kirti','23','Female']];
https://s3-us-west-2.amazonaws.com/secure.notion-static.com/fb0ef8a6-aa80-4132-b035-053042e25d03/Untitled.png

In this way, Arrays with unique index are declared.

Accessing The Multi-Dimensional Array Elements

To Access or Print Element in Array, We should know the Index of Element.

Syntax

arrayName[rowNumber][columnNumber];

Here,

Inside Square Brackets Index of the Element should be placed.

Let's Understand How to Find The Index of Multi-Dimensional Array :

For Example : If it is 2-Dimensional Array, Then you should imagine

2-D Dimensional Array

For Example : If it is 3-Dimensional Array, Then you should imagine

3-D Dimensional Array

Example:

var identity = [['Sam','25','Male'],['Jatin','19','Male'],['Kirti','23','Female']]; console.log(identity[0][0]); console.log(identity[0][1]); console.log(identity[0][2]); console.log(identity[1][0]); console.log(identity[1][1]); console.log(identity[1][2]); console.log(identity[2][0]); console.log(identity[2][1]); console.log(identity[2][2]); // Output // Sam // 25 // Male // Jatin // 19 // Male // Kirti // 23 // Female

Now Try to Visualize This 3-D Dimensional Array.

Copy of 3-D Dimensional Array

Iteration Through Multi Dimensional Array

We, will be using Nested for Loop.

Printing All Elements of Multi-Dimensional Array.

var identity = [['Sam','25','Male'],['Jatin','19','Male'],['Kirti','23','Female']]; var totalLength = identity.length; //2 var i; for(i=0;i
Ask queries
Contact Us on Whatsapp
Hi, How Can We Help You?