DEV Community

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

Posted on

3 1

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}

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free