Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

271
Visualizações
How to delete object and all references?

We use the delete when we need to delete the object reference. But is there any way in JS to delete the entire object and all references?

Example:

let obj = {
    a: 3
}
let arr = [obj];
let brr = [obj];

If I'd change the obj items in the arrays would be changed too. Also, I can use delete arr[0] to delete the reference. But I want to delete the obj and I want the items in the arrays to be deleted too.

Something like:

// Before: 
let obj = {
   a: 3
}
let arr = [obj];
let brr = [obj];
arr.length==1 // true
brr.length==1 // true
// Deleting:
delete(obj)
// After:
arr.length==0 // true
brr.length==0 // true
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

No.

The only way to delete an object in JavaScript is to locate and delete each reference to it.

There's no generic mechanism to start with an object and automatically delete all references to it.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda