javascript

Concatenate multiple objects into one using Javascript

If you have multiple objects and you want to combine them into single object in Javascript then you can use below code.

const user = {
    name: 'John Deo',
    gender: 'Male'
};
const role = {
    admin: '1'
};
const details = {
    email: '[email protected]',
    city: 'New York',
};

const final_object = { ...user, ...role, ...details };

console.log(final_object);

We have three objects user, role, details and we want to make a final object from these three object. We are assigning the combination of these objects to final_object constant.

Live Demo

Was this helpful?