To create a 2D array in JavaScript, nest arrays inside each other, like so:
[ [ 1 ], [ 2 ] ]
.Here's how you do it:
const _2dArray = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
];
console.log(_2dArray[1][1]); // 5
[ [ 1 ], [ 2 ] ]
.Here's how you do it:
const _2dArray = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ]
];
console.log(_2dArray[1][1]); // 5