[英]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.