Stupid JavaScript Tricks

> 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'].


Comments !

blogroll

social