Sha*_*hah 2 typescript angular
我的两个数据需要合并成为一个。我的示例数据是这样的..
第一个数据
{Address: "Test", City: "test", State: "Test"}
Run Code Online (Sandbox Code Playgroud)
第二个数据
{UserId:"John", Name: "John"}
Run Code Online (Sandbox Code Playgroud)
当我使用这种方法时,const a = [].concat(this.firstData, this.secondData);它变成了数组而不是组合成一个,如下所示:
(2)[{…}, {…}]
[0]{Address: "Test", City: "test", State: "Test", …}
[1]{UserId:"John", Name: "John", …}
Run Code Online (Sandbox Code Playgroud)
我应该使用什么方法合并成为一个
您可以在两者上使用扩展运算符:
const firstData = {Address: "Test", City: "test", State: "Test"};
const secondData = {UserId:"John", Name: "John"};
const merged = { ...firstData, ...secondData };
console.log(merged)Run Code Online (Sandbox Code Playgroud)
有用的参考:
| 归档时间: |
|
| 查看次数: |
47 次 |
| 最近记录: |