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

118
Views
How do I create an unique dataset of json object literal in Javascript?

I want to get an output as an unique set of Categories array with the following output [Men,Woman]. Is there any way to do it in Javascript?

For example this my data

{
  "products:"[
    {
      "id": 1,
      "categories": {
        "1": "Men",
      },
    },
    {
      "id": 2,
      "categories": {
        "1": "Men",
      },
    }, {
      "id": 3,
      "categories": {
        "1": "Woman",
      },
    }
  ];
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A simple 1 line answer would be

new Set(input.products.map(p => p.categories["1"]))

This is if you're expecting only key "1" in the categories object.

If it can have multiple categories then you can always do

const uniqueCategories = new Set();

input.products.forEach(p => uniqueCategories.add(...Object.values(p.categories)))

Now you can convert a Set into an array

PS: This is not a ReactJs problem but a pure JS question. You might want to remove the ReactJs tag from this question altogether.

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!