Skip to content

Instantly share code, notes, and snippets.

@sonnyt
Created April 24, 2014 16:54
Show Gist options
  • Save sonnyt/11261593 to your computer and use it in GitHub Desktop.
Save sonnyt/11261593 to your computer and use it in GitHub Desktop.
Merge Objects
function merge(mainObject) {
for (var i = 1; i < arguments.length; i++) {
for (var key in arguments[i]){
mainObject[key] = arguments[i][key];
}
}
return mainObject
}
// Make sure each key is unique
var contact = merge({name: 'John'}, {city: 'Brooklyn'}, {State: 'New York'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment