Defining 2D array Javascript

The variable leds needs to be defined as an array before it can be used as one. Then you can add elements to it using the push method; and these elements can be other (nested) arrays. For example:

//set leds as an empty array
let leds = [];

//add to the array
leds[0] = [1,2,3];

leds[1] = [4,5,6];


//change an array value
leds[1][1] = 0;


CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top