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

89
Visualizações
Delete array object in java script

I have an array of object and it looks like this, I want to remove attributeType object and get a new one. How can I delete object in array?

{
    "id": 2,
    "version": 1,
    "name": "test",
    "attributeInputs": {
        "0": {
            "id": 4,
            "position": 0,
            "label": "display",
            "attributeType": {
                "id": 3,
                "label": "Input",
                "fieldType": "TEXT"
            },
        },
        "1": {
            "id": 5,
            "position": 3,
            "label": "price",
            "attributeType": {
                "id": 5,
                "label": "Price",
                "fieldType": "PRICE"
            },
        }
    }
}

I would like delete AttributeType and it should look like this:

{
    "id": 2,
    "version": 1,
    "name": "test",
    "attributeInputs": {
        "0": {
            "id": 4,
            "position": 0,
            "label": "display",
        },
        "1": {
            "id": 5,
            "position": 3,
            "label": "price",
        }
    }
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use Object.keys() on the attributeInputs field and delete the key attributeType:

const obj = {
    "id": 2,
    "version": 1,
    "name": "test",
    "attributeInputs": {
        "0": {
            "id": 4,
            "position": 0,
            "label": "display",
            "attributeType": {
                "id": 3,
                "label": "Input",
                "fieldType": "TEXT"
            },
        },
        "1": {
            "id": 5,
            "position": 3,
            "label": "price",
            "attributeType": {
                "id": 5,
                "label": "Price",
                "fieldType": "PRICE"
            },
        }
    }
}

Object.keys(obj.attributeInputs).forEach(o => delete obj.attributeInputs[o].attributeType )

console.log(obj)

about 4 years ago · Juan Pablo Isaza Relatório

0

first, let's store the object in a variable called myObject. now let's work on the variable myObject.

myObject.attributeInputs = Object.keys(myObject.attributeInputs).map(key=>{
    const {attributeType,...newObj}=myObject.attributeInputs[key];
    return newObj;
});

it's not clean code, but it works.

about 4 years ago · Juan Pablo Isaza 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