DEV Community

Cover image for How To Copy Properties from an Object To Another?
Islam Sayed
Islam Sayed

Posted on

How To Copy Properties from an Object To Another?

Rest operator is awesome. Here is how to copy properties from one object to another using Spread operator.

//copy properties from an object to another one
//using SPREAD OPERATOR.
const obj1 = {
    a: 2,
    b: 5
}
const obj2 = {
    ...obj1,
    c: 6
} //{a: 2, b: 5, c: 6}

Discussion (0)