var arrayX = [ ["fire", "lightning"], [3, "ice"], [85], ["wind", "earth", 0] ];
In the example above, arrayX
consists of four elements, each of which is also an array. As it stands now, arrayX.length
equals 4
.
I wonder if it is possible to remove all the four pairs of square brackets inside, leaving only the most outer bracket, so that the computer can now count the total number of all the individual elements in arrayX
. I mean, like this:
var arrayX = ["fire", "lightning", 3, "ice", 85, "wind", "earth", 0];
Now, arrayX.length
returns 8
, and this is the number I want to get. I started to learn programming just several days ago, so I'm not sure how to go about this. Thank you in advance.