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

Publicado em: 25 Outubro 2022
no canal de: 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


Nesta página do site você pode assistir ao vídeo on-line JavaScript tips — Initialize an array with a given value using Array.fill duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Code 2020 25 Outubro 2022, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 194 vezes e gostou 5 espectadores. Boa visualização!