Created
December 13, 2012 00:25
-
-
Save thisandagain/4272981 to your computer and use it in GitHub Desktop.
Hash stuff for jlord
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
// Starting point | |
var array = [ | |
{ | |
id: 1, | |
title: 'Hello', | |
tools: [1,2,3] | |
}, | |
{ | |
id: 2, | |
title: 'World', | |
tools: [2,3,4] | |
}, | |
{ | |
id: 3, | |
title: 'FooBar', | |
tools: [3,4,5] | |
} | |
]; | |
// Storage object | |
var hash = Object.create(null); | |
// Iterate | |
for (var i = 0; i < array.length; i++) { | |
var uniqueId = array[i].id; | |
hash[uniqueId] = array[i]; | |
} | |
console.dir(hash); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment