DekGenius.com
JAVASCRIPT
merge two objects javascript
const object1 = {
name : 'Flavio'
}
const object2 = {
age : 35
}
const object3 = { ... object1, ... object2 }
merge objects javascript
const a = { b : 1 , c : 2 } ;
const d = { e : 1 , f : 2 } ;
const ad = { ... a, ... d } ;
merge two objects javascript
Object . assign ( target, sourceObj1, sourceObj2, ... ) ;
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 } ;
merge objects js
Object . assign ( obj1, obj2) ;
const allRules = Object . assign ( { } , obj1, obj2, obj3, etc) ;
javascript combine objects
const obj1 = { 'a' : 1 , 'b' : 2 } ;
const obj2 = { 'c' : 3 } ;
const obj3 = { 'd' : 4 } ;
const objCombined = { ... obj1, ... obj2, ... obj3} ;
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) ;
} , { } ) ;
javascript merge objects
export function isObject ( item ) {
return ( item && typeof item === 'object' && ! Array . isArray ( item) ) ;
}
export function mergeDeep ( target, ... sources ) {
if ( ! sources. length ) return target;
const source = sources. shift ( ) ;
if ( isObject ( target) && isObject ( source) ) {
for ( const key in source) {
if ( isObject ( source[ key] ) ) {
if ( ! target[ key] ) Object . assign ( target, { [ key] : { } } ) ;
mergeDeep ( target[ key] , source[ key] ) ;
} else {
Object . assign ( target, { [ key] : source[ key] } ) ;
}
}
}
return mergeDeep ( target, ... sources) ;
}
© 2022 Copyright:
DekGenius.com