Initialize array of given size in Javascript

hkirat profile image harkirat singh ・1 min read

If you want to initialize an array that you don't need to iterate over -

Array(100) or new Array(100)

If you do need to iterate over it -

Array.from({length: 5}, (v, i) => i) 


markdown guide

Just an adder: If you want to initialise it with say, all 0s or some number.. You can also do new Array(100).fill(0)