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).
2.1m questions
2.1m answers
60 comments
56.9k users