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

220
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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