Question : javascript array
Answered by : code-grepper
//create an array like so:
var colors = ["red","blue","green"];
//you can loop through an array like this:
for (var i = 0; i < colors.length; i++) { console.log(colors[i]);
}
Source : | Last Update : Mon, 08 Jul 19
Question : javascript initialize array
Answered by : exuberant-eland-k07948nw359u
const array = new Array(5).fill(0);
console.log(array);
// [0, 0, 0, 0, 0]
Source : https://attacomsian.com/blog/javascript-array-populate | Last Update : Mon, 13 Dec 21
Question : Declare and Initialize Arrays in javascript
Answered by : poised-peacock-8kfifgk36e8r
const array = Array(5).fill('');
// Output
(5) ["", "", "", "", ""]
const matrix = Array(5).fill(0).map(()=>Array(5).fill(0));
// Output
(5) [Array(5), Array(5), Array(5), Array(5), Array(5)]
0: (5) [0, 0, 0, 0, 0]
1: (5) [0, 0, 0, 0, 0]
2: (5) [0, 0, 0, 0, 0]
3: (5) [0, 0, 0, 0, 0]
4: (5) [0, 0, 0, 0, 0]
length: 5
Source : https://dev.to/devsimc/javascript-best-practices-44ll | Last Update : Mon, 25 Jul 22
Question : How to initialize an array
Answered by : mvp
my @array = ();
Source : | Last Update : Mon, 18 Jul 22