3 ms·
I stumbled upon a few of the mentioned tricks in the article lately, while working on JavaScript projects in my spare time. Another little trick that I persona
by giu 16y ago
I stumbled upon a few of the mentioned tricks in the article lately, while working on JavaScript projects in my spare time.
Another little trick that I personally like because of its simplicity is the following:
Array.prototype.clear = function(){this.length=0;}
Clears an Array the easy way.
- lhorie 16y agoYou just need to be aware that this might cause unexpected behavior when using for ... in Array.prototype.clear = function() {this.length = 0}; var a = [1,2,3]; var s = ""; for(var i in a) s += i +","; alert(s);//1,2,3,clear (not that many people use it this way, but since we're on the topic of little known tricks about js, I think it's worth mentioning)