Say I have the following object:
var obj = { foo: 'bar' };
I want to add this object to an array X amount of times so the result is:
[{ foo: 'bar' }, { foo: 'bar'}, ... , { foo: 'bar'}]
Is there a way to accomplish this without explicitly coding a loop?
There is a way: manually. Any programmatic solution will indeed use a loop here, which, if you wish to maintain your sanity -- use it.
You can use map
var filled = Array.apply(null, Array(501)).map(function() { return {"foo":"bar"} });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With