Friday 19 January 2018

How can I create a two dimensional array in JavaScript?

itemprop="text">


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




data-hide="false" data-console="true" data-babel="false">
class="snippet-code">

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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...