Created
July 18, 2012 16:27
-
-
Save sifu/3137305 to your computer and use it in GitHub Desktop.
set a default value for a key and push to it in one line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = [ 'one', 'two', 'one', 'one' ]; | |
var result = {}; | |
a.forEach( function( key ) { | |
( result[ key ] || ( result[ key ] = [] ) ).push( key ) | |
} ); | |
console.info( result ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment