Array 'fill' method in Javascript (Array.prototype.fill)

preview_player
Показать описание
The 'fill' method allows you to fill an array with a single value that you pass in. This is clearly useful if you wanted to change the value of all elements in an array at once.

With objects however, only one object gets created and each element instead has a reference to that object. Instead you'll want to use the 'map' method to achieve the same effect - which we also cover in this video.

For your reference:

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

Had a problem using the .fill() array method for a advanced software design course I am taking and this perfectly explains why .fill() wasn't the right method to use! Thank you!!

codygrimes
Автор

I hope you're not using a mechanical keyboard for your vids like wtf were you thinking bruh

JedOpeningThings
Автор

Not sure how this would be useful though! :)

smoothbeak