Is there a more compact way to do this sort of initialization?
for (var i = 0; i < arraySize; i++) array[i] = value;
One short way of doing it would be:
var arr = Array(arraySize).fill(value);
Would make arr = Array [ 0, 0, 0, 0, 0 ] if arraySize == 5 and value == 0, for example.
arr = Array [ 0, 0, 0, 0, 0 ]
arraySize == 5
value == 0
1.4m articles
1.4m replys
5 comments
57.0k users