Angular 5一个列表仅使用行和列索引推送到另一个列表

时间:2018-10-09 05:35:42

标签: javascript angular5

在angular 5中,如何仅使用到ListB的行列索引获取静态listA记录。不使用component.ts文件中的Column标头。您能帮帮我吗

ListA=[{Id:0,Name:Babu},{Id:1,Name:raju}] // here ListA is static list.

新的ListB将采用

的形式
[{A:1,B:Babu},{A:2,B:raju}] // here B column record as ListA Column "Name" record.

1 个答案:

答案 0 :(得分:0)

You can use the array.map function to generate your new array:

let listB = listA.map((item) => {A: item.Id, B:item.Name});

By the way, unless your Name property values is a variable, you should add quotes around it. Like this:

ListA=[{Id:0,Name:"Babu"},{Id:1,Name:"raju"}]

Hope this helps...