Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

88
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda