When I try to create a multidimensional array, I accidentally forgot to add ,
in between each sub-array.
const multi = [["first", 1]["second", 2]["third", 3]["fourth", 4]];
And I found that with browser console it gives an error in some occasions, and it declares the array in some occasions. Below are what I tried with Firefox web browser console,
First, I try to put ,
after the first sub-array.
const multi2 = [["first", 1], ["second", 2]["third", 3]["fourth", 4]];
return ==> Uncaught TypeError: ["second", 2][3] is undefined
But if I add ,
after the second sub-array, it will declare the multidimensional array.
const multi3 = [["first", 1], ["second", 2], ["third", 3]["fourth", 4]];
And when I try multi3
on console it will display the array and the value of the 3rd element is undefined
. And the length of mult3
is 3.
Can you please explain why this is happening?