javascript merge code example
Example 1: javascript merge objects
var person={"name":"Billy","age":34};
var clothing={"shoes":"nike","shirt":"long sleeve"};
var personWithClothes= Object.assign(person, clothing);
Example 2: how to merge two objects into one in javascript
let obj1 = { foo: 'bar', x: 42 };
let obj2 = { foo: 'baz', y: 13 };
let clonedObj = { ...obj1 };
let mergedObj = { ...obj1, ...obj2 };
Example 3: merge objects js
Object.assign(obj1, obj2);
const allRules = Object.assign({}, obj1, obj2, obj3, etc);
Example 4: concat object
const obj1 = { food: 'pizza', car: 'ford' };
const obj2 = { animal: 'dog' };
const obj3 = { ...obj1, ...obj2 };
console.log(obj3);
Example 5: array merge in javascript
function mergeArrays(arr1, arr2) {
return Array.from(new Set(arr1.concat(arr2).sort((a,b) => (a-b))));
}