Create arrays and initiate data in a single statement.
Traditionally you would do the below to initiate the array and fill it with values -
|
|
This is a-ok if you know the values, but what if you want array to have fixed elements with pre-defaulted values? This is where fill
(an ES6 feature) steps in.
|
|
You could also instantiate only certain elements of the array as well.
|
|
fill
is both fast and efficient. But it can support instantiating with a single value.
We do not have a comparable feature for objects - it may not make a lot of sense to create ten empty properties :)