I two data need to merge become one. My example data like this..
First data
{Address: "Test", City: "test", State: "Test"}
Second Data
{UserId:"John", Name: "John"}
When I use this method const a = [].concat(this.firstData, this.secondData); it become in array not combine become one, example like bellow:
(2)[{…}, {…}]
[0]{Address: "Test", City: "test", State: "Test", …}
[1]{UserId:"John", Name: "John", …}
What method should I use to merge become one
You can use the spread operator on both:
const firstData = {Address: "Test", City: "test", State: "Test"};
const secondData = {UserId:"John", Name: "John"};
const merged = { ...firstData, ...secondData };
console.log(merged)
Useful references:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With