0
I have an array called listAtributos: any[] = []; and I need to remove the lines that match my index.
If I give a console log in this way, it shows me exactly the elements that should be deleted:
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 switch to the splice function, only the first element is deleted, having to double-click the button that calls this delete function.
You shouldn’t erase the two since you’re in a repeating 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 of input:
My object listAtributes 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 lines where the indexvariacaoatributo equals the index passed in the removeAtributo function()
If my index is passed in parameter 1, it should be removed:
2: {indexvariacaoatributo: 1, id: 5, tipovariacao: "Cor", valorvariacao: "Azul"}
3: {indexvariacaoatributo: 1, id: 7, tipovariacao: "Tamanho", valorvariacao: "P"}
Please provide an example input with the expected output
– echojn
I gave a changed, see if now is giving to understand better
– veroneseComS