I have an array called listAttributes: any [] = []; and I need to remove the rows that match my index.
If I give a console log this way, it shows me exactly which elements should be excluded:
removeAtributo(index: number){
for(let i=0;i<this.listAtributos.length;i++){
if(this.listAtributos[i].indexvariacaoatributo == index){
console.log(this.listAtributos[i])
}
}
}
But when I change to the splice function, only the first element is deleted, having to double-click the button that calls this exclude function.
Should not you delete the two since it's in a repeat structure?
With the splice:
removeAtributo(index:number){
for(let i=0;i<this.listAtributos.length;i++){
if(this.listAtributos[i].indexvariacaoatributo == index){
this.listAtributos.splice(i,1)
}
}
}
Example input:
My listAttributes object has:
0: {indexvariacaoatributo: 0, id: 5, tipovariacao: "Cor", valorvariacao: "Azul"}
1: {indexvariacaoatributo: 0, id: 6, tipovariacao: "Cor", valorvariacao: "Amarelo"}
2: {indexvariacaoatributo: 1, id: 5, tipovariacao: "Cor", valorvariacao: "Azul"}
3: {indexvariacaoatributo: 1, id: 7, tipovariacao: "Tamanho", valorvariacao: "P"}
I need to remove the rows where the indexvariance attribute equals the index passed in the function removeAttribute ()
If my index passing in parameter is 1, you must remove:
2: {indexvariacaoatributo: 1, id: 5, tipovariacao: "Cor", valorvariacao: "Azul"}
3: {indexvariacaoatributo: 1, id: 7, tipovariacao: "Tamanho", valorvariacao: "P"}