JavaScript tips — Initialize an array with a given value using Array.fill

Опубликовано: 25 Октябрь 2022
на канале: Code 2020
194
5

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


На этой странице сайта вы можете посмотреть видео онлайн JavaScript tips — Initialize an array with a given value using Array.fill длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Code 2020 25 Октябрь 2022, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 194 раз и оно понравилось 5 зрителям. Приятного просмотра!