I need to remove an attribute from my object (indexvariance attribute), but I need it to stay in the root object.
This is my algorithm that receives in the variable my object variable and then I remove the indexvariacao attribute attribute of the object, in this way the algorithm works perfectly, but apart from the variable variables, it is also removed from the variable categoryForm:
var variacoes = categoriaForm.variacoes
if(variacoes[0].estoque_variacao == null || variacoes[0].estoque_variacao == 0){
variacoes = [];
}
//Retira do objeto o indexvariacaoatributo
for(let i=0;i<variacoes.length;i++){
for (let j=0;j<variacoes[i].atributo.length;j++){
console.log(variacoes[i].atributo[j].indexvariacaoatributo);
delete variacoes[i].atributo[j].indexvariacaoatributo
}
}
console.log(variacoes);
I tried to make a copy without reference of these forms:
var variacoes = Object.assign({}, categoriaForm.variacoes);
I've also tried:
var variacoes = { ...categoriaForm.variacoes };
But these two ways, when I start the variable variation I realize that my index is still there. I put that console.log and I noticed that it is not entering inside my for.
Is there anything else that needs to be done when copying an object in this way?