Is there a way to assign a default values to arrays in javascript?
ex: an array with 24 slots that defaults to 0
an array with 24 slots that defaults to 0
You can use the fill function on an array:
fill
Array(24).fill(0)
Note: fill was only introduced in ECMAScript 2015 (alias "6"), so as of 2017 browser support is still very limited (for example no Internet Explorer).
1.4m articles
1.4m replys
5 comments
57.0k users