Need to create an array of a given size where all the entries in it have been initialized to a given number or string value? Just use the new Array constructor and the fill method:
new Array(size).fill(initialValue)
This also works for typed arrays, such as Uint8Array. It is much more concise (and faster) than doing this with a for loop yourself
#javascript
On this page of the site you can watch the video online JavaScript tips — Initialize an array with a given value using Array.fill with a duration of hours minute second in good quality, which was uploaded by the user Code 2020 25 October 2022, share the link with friends and acquaintances, this video has already been watched 194 times on youtube and it was liked by 5 viewers. Enjoy your viewing!