4 ms·
Why never use new Array in Javascript
I love Javascript, but sometimes it seems it doesn't love me back. Take for instance the Array constructor function...
- bdfh42 14y agoI agree that var a = new Array(1,2,3,4,5); is an old construct and should be replaced by var a = [1,2,3,4,5]; but the form var a = new Array(10); can be very effective when you need an array with n elements and you are not in a position to .push() new ones in - you just need those elements to be there. No confusion here - just lots of helpful language features.
- dragonbonheur 14y agoThose arrays are behaving exactly how arrays behave in any language. Can't see the problem here.