Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!