JavaScript multi dimensional arrays

In JavaScript, we can create multi-dimensional arrays.
Check out all 100 + JavaScript Examples
Check out all JavaScript programs at All JavaScript Programs 

JavaScript multi-dimensional arrays

A multi-dimensional array is created by nesting arrays into other arrays.
const nums = [2, 3, 2, [33, 44, 55], [7, 8, [77, 88]]];

console.log(nums[2]);

console.log(nums[3]);
console.log(nums[3][0]);

console.log(nums[4][0]);
console.log(nums[4][2][0]);
We have a multi-dimensional array defined:
const nums = [2, 3, 2, [33, 44, 55], [7, 8, [77, 88]]];
To get an element from the first dimension, we use a single pair of square brackets:
console.log(nums[2]);
This line prints the entire inner array:
console.log(nums[3]);
To get an element from an inner array, we use two pairs of brackets:
console.log(nums[3][0]);
Here we get a value from the third dimension:
console.log(nums[4][2][0]);
This is the output:
2
[ 33, 44, 55 ]
33
7
77
Check out all 100 + JavaScript Examples
Check out all JavaScript programs at All JavaScript Programs 

Comments