About
This dependency reimplements the Object.assign
method which is used to shallowly copy properties from one or more source objects to a target object.
It also needs 4 dependencies to do what Object.assign
can do natively.
// merge 2 objects
const obj1 = {
foo: "bar"
};
const obj2 = {
baz: "qux"
};
const merged = Object.assign({}, obj1, obj2);
console.log(merged); // { foo: "bar", baz: "qux" }
or you can use the spread
operator for a more concise syntax:
// merge 2 objects
const obj1 = {
foo: "bar"
};
const obj2 = {
baz: "qux"
};
const merged = {
...obj1,
...obj2
};
console.log(merged); // { foo: "bar", baz: "qux" }
The spread
operator is supported by all modern browsers and Node.js versions since about 9 years.