[英]How to merge two or more arrays in angular 11
我有两个来自 url 的 arrays。 我正在尝试将两个 arrays 作为单个数组加入 angular
"admin":[ { "Name":"John", "Age":34 }, { "Name:"Joe", "Age":56 } ], "users":[ { "Name":"John", "Age":34 }, { "Name:"Joe", "Age":56 } ]
我试图通过加入两个 arrays
public newArr=[]; join(){ this.newArr=this.newArray.concat(this.admin,this.users) console.log(this.this.newArr.length); //the result shown in the console is 0 }
我尝试了另一种方法
join(){ this.newArr.push(...this.users,...this.admins) console.log(this.newArr.length) //the results is still 0 }
请问我该怎么做 go 关于那个
只需使用解构赋值。 您可以在此页面获取更多信息
public newArr=[...this.admin,...this.users];
public newArr=[];
join(){
this.newArr=this.admin.concat(this.users)
console.log(this.newArr.length);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.