[Blog] Stupid JavaScript Tricks

Craig Maloney at 2016-12-29T02:00:08Z

(http://feedproxy.google.com/~r/CraigMaloney/~3/oGYw3Xl6x7I/)

> bar = ['width', 'height']
[ 'width', 'height' ]
> bar
[ 'width', 'height' ]  // Nothing up my sleeve
> bar.indexOf['length']
1  // Presto!

In case you haven't guessed what's up here: JavaScript automatically surfaces a value called 'length' in all arrays. So you can get the length of bar by typing bar.length and bar['length'].