react merge objects code example
Example 1: merge properties of object typescript
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };
const returnedTarget = Object.assign(target, source);
Example 2: merge objects javascript
const a = { b: 1, c: 2 };
const d = { e: 1, f: 2 };
const ad = { ...a, ...d };
Example 3: spread operator merge objects
let a = {
a: 1,
b: true
}
let b = {
y: 093,
z: 'This is an object'
}
const c = {...a, ...b}
Example 4: Merging Or Copying Arrays Using Spread Operator
let techlist1= ['spring', 'java'];
let techlist2= ['javascript', 'nodejs', 'mongo'];
let fullstacklist= […techlist1, …techlist2];
console.log(fullstacklist);
Example 5: react merge two objects
const object1 = {
name: 'Flavio'
}
const object2 = {
age: 35
}
const object3 = {...object1, ...object2 }
Example 6: two object combine together javascript
const a = { b: 1, c: 2 };
const d = { e: 1, f: 2 };
const ad = { ...a, ...d };
let objs = [{firstName: "Steven"}, {lastName: "Hancock"}, {score: 85}];
let obj = objs.reduce(function(acc, val) {
return Object.assign(acc, val);
},{});