Skip to content

Instantly share code, notes, and snippets.

@codeBelt
Created November 26, 2013 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeBelt/7662614 to your computer and use it in GitHub Desktop.
Save codeBelt/7662614 to your computer and use it in GitHub Desktop.
JavaScript Hash union.
var arrayOfProperties = [
'admin',
'user',
'anon'
];
var hash = {
admin: "Admin",
user: "user",
superadmin: 'SuperAdmin'
}
var i;
var key;
var unionHash = {};
for (i = 0; i < arrayOfProperties.length; i++) {
key = arrayOfProperties[i];
if (key in hash) {
unionHash[key] = hash[key];
}
}
return unionHash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment