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?
Similar Posts
- how to merge two dimensional array into one dimensional
- Combine or merge two or multiple arrays into single array in Javascript
- Merge multiple arrays and strings into single array using Lodash
- Break an array into fixed length array groups using lodash in Javascript
- Javascript to split string into array of characters
- Sort array of objects by key value in Javascript
- Lodash - Get all elements of array except the last one