Chrome Extension

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@domain.com',
    city: 'New York',
};

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

console.log(final_object);
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

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?
0 Comments