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

216
Vistas
How to remove key data from all rows from json array using javascript

This is a JSON array. I want to remove the productID from all the rows. when I console log I don't want to see the productID in it.

"items": 
            [
                { 
                    "productID": "11234567",
                    "added": "TIMESTAMP",
                    "title": "Project",
                    "type": "Weekend Project",
                    "imageURL": "1"
                },

                { 
                    "productID": "11223456",
                    "added": "TIMESTAMP",
                    "title": "Bathroom",
                    "type": "Weekend Project",
                    "imageURL": "2"
                },

                { 
                    "productID": "11223345",
                    "added": "TIMESTAMP",
                    "title": "Curves",
                    "type": "Collections",
                    "imageURL": "3"
                }
            ]

The issue was I faced :

I needed to export the array in excel format. I got a simple function for it. but I have to remove some contents from the original JSON which is coming from the backend.

i checked lots of threads in StackOverflow but i cant find the correct solution.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You could use spread syntax

const data = [{
    "productID": "11234567",
    "added": "TIMESTAMP",
    "title": "Project",
    "type": "Weekend Project",
    "imageURL": "1"
  },

  {
    "productID": "11223456",
    "added": "TIMESTAMP",
    "title": "Bathroom",
    "type": "Weekend Project",
    "imageURL": "2"
  },

  {
    "productID": "11223345",
    "added": "TIMESTAMP",
    "title": "Curves",
    "type": "Collections",
    "imageURL": "3"
  }
]

const result = data.map(p => {
  const { productID, ...rest } = p;
  return { ...rest };
});

console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar

0

assuming

const items =
            [
                { 
                    "productID": "11234567",
                    "added": "TIMESTAMP",
                    "title": "Project",
                    "type": "Weekend Project",
                    "imageURL": "1"
                },

                { 
                    "productID": "11223456",
                    "added": "TIMESTAMP",
                    "title": "Bathroom",
                    "type": "Weekend Project",
                    "imageURL": "2"
                },

                { 
                    "productID": "11223345",
                    "added": "TIMESTAMP",
                    "title": "Curves",
                    "type": "Collections",
                    "imageURL": "3"
                }
            ]

You can just iterate through all elements and delete id property:

items.forEach(o=>delete o.productID)

or map it into desired structure
const newItems = items.map((o)=>({"title":o.title,"added":o.added}))

Edit:
In first approach you don't need to create new variable, you edit orginal one, in other one you get new object so you have to assign it to new variable.

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