3

I have select many data and post to back end, it is succeed but after that i want to delete array data in front end without reload. I try with splice it is only delete one or two max is tow

Here is my code

const itemOrder = this.baskets.filter((el)=>{
    return el.checkbox == true
});

HTTP().post('/order',itemOrder).then(()=>{
});

after then i wont to delete all this baskets if checkbox is true

i have try

for(let i in this.baskets) {
    if(this.baskets[i].checkbox == true) {
        console.log(i);
        this.baskets.splice(i,1);
    }
}

and also try this

this.baskets.splice(this.baskets.findIndex(e => e.checkbox == true),1);

still does not work as my expectation

1 Answer 1

1

You can filter all false checkboxes:

let baskets = [
  {id: 1, checkbox: true},
  {id: 2, checkbox: true},
  {id: 3, checkbox: false},
  {id: 4, checkbox: true},
  {id: 5, checkbox: true}
]

baskets = baskets.filter(b =>  b.checkbox === false)

console.log(baskets)

Sign up to request clarification or add additional context in comments.

Comments

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.