Angular Typescript:将一个数组筛选为另一个数组
我有一个对象数组“inputData”,如下所示:Angular Typescript:将一个数组筛选为另一个数组,angular,typescript,filter,ecmascript-6,ecmascript-5,Angular,Typescript,Filter,Ecmascript 6,Ecmascript 5,我有一个对象数组“inputData”,如下所示: [{code:"11" , name= "test1" , state:"active" , flag:"stat"}, {code:"145" , name= "test2" , state:"inactive" , flag:"pass"}, {code1:"785" , name= "test3" , state:"active" , flag:"stat"}, ... ] 在不循环它的情况下,我想过滤它以获得一个ouputData数组
[{code:"11" , name= "test1" , state:"active" , flag:"stat"},
{code:"145" , name= "test2" , state:"inactive" , flag:"pass"},
{code1:"785" , name= "test3" , state:"active" , flag:"stat"},
...
]
在不循环它的情况下,我想过滤它以获得一个ouputData数组,如下所示:
[{id:"11" , libelle= "test1"},
{id:"145" , libelle= "test2"},
{id:"785" , libelle= "test3"},
...
]
在哪里
代码->id
及
姓名->诽谤
建议???您可以将阵列映射到另一个阵列
const outputData=inputData.map({code:id,name:libelle})=>({id,libelle}))
请注意,我正在使用一些
es6
功能,如参数和 为什么不循环?你试过什么?展示你自己编写的代码来尝试自己做吗?我认为map
是ES5的一部分,而不是ES6?