Skip to content

Instantly share code, notes, and snippets.

@HarasimowiczKamil
Created March 18, 2016 08:45
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 HarasimowiczKamil/23d24b1e96df393f12c4 to your computer and use it in GitHub Desktop.
Save HarasimowiczKamil/23d24b1e96df393f12c4 to your computer and use it in GitHub Desktop.
Merge objects in javascript
/**
* Merge objects
*
* @param {...object} obj
*
* @return {object}
*/
function merge() {
var i, obj, key,
result = {};
for (i = arguments.length - 1; i >= 0; i--) {
obj = arguments[i];
for (key in obj) {
if (obj.hasOwnProperty(key)) {
result[key] = obj[key];
}
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment