3 ms·
Since I started using JS heavily lately, it's nice to be reminded of some things. Thanks for posting. One question though, it says: If you want to append
by babuskov 13y ago
Since I started using JS heavily lately, it's nice to be reminded of some things. Thanks for posting.
One question though, it says:
If you want to append an item to an array, the safest way to do it is like this:
a[a.length] = item; // same as a.push(item);
a.push() variant seems more elegant to me. Why is a[] variant "safer"?
- bpierre 13y agoIt must be for the compatibility, Array.prototype.push() has been added to IE 5.5: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push#Browser_compatibility https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- unstabilo 13y agoBoth methods are equally safe, what the author meant is that both are safer than a[14] = item or a[myCounter] = item.