I want to create 10 Fly objects in a functional manner. I thought this would work:
var flies = new Array(10).map(function() {
return new Fly();
});
It doesn't. It creates an array of length ten with undefined as their values.
How can I create 10 objects without using for(var i = 0; i < 10; i++)...?
EDIT: This is an academic exercise for the sake of learning only. It's find if a for is used under the hood. I'm just trying to figure out what JavaScript can do.
Array.apply(0, Array(10)).mapfor?[0,1,2,3,4,5,6,7,8,9].map- if you're dead set againstforcallback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes that are undefined, those which have been deleted or which have never been assigned values.Array.from({length: 10}, _ => new Fly());