DEV Community

loading...

Discussion on: 17 Pro JavaScript tricks you didn't know

Collapse
dotorimook profile image
dotorimook

Thank you for the nice post.

For Populating array,

const array = [...new Array(arraysize)].map(() => ({'hello' : 'goodbye'}));
Enter fullscreen mode Exit fullscreen mode

would also work. I prefer to use this ☺

Collapse
iminside profile image
Dan Chu

What about this?

const array = Array.from({ length: arraysize }, () => ({ hello: 'goodbye' }))
Enter fullscreen mode Exit fullscreen mode

And if rename arraysize to length then

const array = Array.from({ length }, () => ({ hello: 'goodbye' }))
Enter fullscreen mode Exit fullscreen mode