How can I create a two dimensional array in JavaScript

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

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.

    • How do I declare a 2 dimensional array in JavaScript? (assuming it s possible)
    • How would I access its members? (myArray[0][1] or myArray[0,1]?)

Answers

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

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/966225/how-can-i-create-a-two-dimensional-array-in-javascript

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils