1

I have some compllex component which contains array

this.SomeComponent.subArray

SomeComponent:model1;

model1 definition:

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

model2 definition:

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

Now if I console.log(JSON.stringify(this.SomeComponent.subArray)); I get :

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

Now my task is to delete subArray part which has someString23==red. So When I console log next time I must get only this

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

How can I do that?

1
  • question solved, thanks to Aakash Garg and Michael D. You guys rock! :) Commented Jun 7, 2020 at 12:07

1 Answer 1

1

Use filter method like below :-

this.subArray = subArray.filter((item) => item["someString23"]!==red);
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Akash Garg, I've update question. I want to actually delete that part so after new console.log it must not be displayed
Aakash Garg thanks, so filter deletes component. Thats great. And what directive adds component to array ? can u write quick line of code ?
subArray.push(component).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.