Skip to content

Instantly share code, notes, and snippets.

@thisandagain
Created December 13, 2012 00:25
Show Gist options
  • Save thisandagain/4272981 to your computer and use it in GitHub Desktop.
Save thisandagain/4272981 to your computer and use it in GitHub Desktop.
Hash stuff for jlord
// 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