从对象中删除数组组件

问题描述 投票:1回答:1

我有一些包含数组的compllex组件

this.SomeComponent.subArray

SomeComponent:model1;

model1定义:

someString1:string;
someString2:string;
someString3:string;
subArray[]

model2定义:

someString22:string;
someString23:string;
someString24:string;

现在,如果我console.log(JSON.stringify(this.SomeComponent.subArray));我得到:

SomeComponent[{"someString22":"one","someString23":"yellow","someString24":"water",},
{"someString22":"two","someString23":"red","someString24":"ground",}
{"someString22":"three","someString23":"green","someString24":"air",}]

现在我的任务是删除具有subArraysomeString23==red部分。因此,当我下次控制台日志时,我只能得到此

SomeComponent[
    {"someString22":"two","someString23":"red","someString24":"ground",}
    {"someString22":"three","someString23":"green","someString24":"air",}]

我该怎么做?

arrays angular delete-row splice
1个回答
0
投票

使用如下过滤方法:-

console.log(subArray.filter((item) => item["someString23"]!==red));
© www.soinside.com 2019 - 2024. All rights reserved.