Thursday, October 31, 2019

How can I create a two dimensional array in JavaScript?



I have been reading online and some places say it isn't possible, some say it is and then give an example and others refute the example, etc.





  1. How do I declare a 2 dimensional array in JavaScript? (assuming it's possible)


  2. How would I access its members? (myArray[0][1] or myArray[0,1]?)



Answer





var items = [
[1, 2],

[3, 4],
[5, 6]
];
console.log(items[0][0]); // 1
console.log(items[0][1]); // 2
console.log(items[1][0]); // 3
console.log(items[1][1]); // 4
console.log(items);





No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...