Tech Study

JavaScript Multidimensional Array

JavaScript Multidimensional Array

A multidimensional array in JavaScript is an array that contains one or more arrays as elements. These arrays can be thought of as matrices where each array element represents a single value and each row or column represents a single dimension.

Arrays in JavaScript are usually one-dimensional. That is, there is only one element level. However, nesting arrays allows you to create multidimensional arrays.

Here is an example of a javascript multidimensional array

let matrix = [

  [1, 2, 3],

  [4, 5, 6],

  [7, 8, 9]

];

Example:

var fruits1 = [ ["apple", "red", "sweet"], 

["banana", "yellow", "tropical"], 

["orange", "orange", "citrus"] ];

// accessing the first fruit's properties 

console.log("The " + fruits1[0][0] + " is " + fruits1[0][1] + " and " + fruits1[0][2] + ".");




// updating a fruit's property 

fruits1[1][1] = "brown";




// adding a new fruit to the array 

fruits1.push(["grape", "purple", "juicy"]);




// looping through the array and displaying each fruit's properties 

for (var j = 0; j < fruits1.length; j++) 


console.log("The " + fruits1[j][0] + " is " + fruits1[j][1] + " and " + fruits1[j][2] + "."); 

}

Output:

The apple is red and sweet.

The apple is red and sweet.

The banana is brown and tropical.

The orange is orange and citrus.

The grape is purple and juicy.

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more