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

Pubblicato il: 25 ottobre 2022
sul canale di: 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


In questa pagina del sito puoi guardare il video online JavaScript tips — Initialize an array with a given value using Array.fill della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Code 2020 25 ottobre 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 194 volte e gli è piaciuto 5 spettatori. Buona visione!