In my angular2 application which contains checkboxes; the checkbox keys are stored in an array named "ticketselected" and the selected check boxes keys are stored in "selectedArray". I want to assign these keys one by one to a variable and use that variable. I need to splice an array. How can I implement this?
what I have done is:
component.ts
this.ticketSelected
.map((entry, key) => {
if (entry == true) {
selectedArray.push(key);
}
})
var index = // This should be key
allTickets.splice(index, 1);
'selectedArray' contains all selected keys.
How should I implement this?
EDIT
deleteRequest
.subscribe((data: any) => { // this data contain deleted data ie like {count:1}
this.ticketSelected
.map((entry, key) => {
if (entry === true) {
selectedArray.push(key);
}
})
selectedArray.forEach((item) => {
var index = allTickets.indexOf(item);
console.log("index", index);
if (index != -1){
allTickets.splice(index, 1);
}
});
})
entry == truewithentry === trueif you want to check the value ofentry. Otherwise, that condition is going to betruefor any truthy value.