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

191
Views
Get unique category property values from an array
const array = [{
        productname: "productname1",
        category: "category1"
    },
    {
        productname: "productname2",
        category: "category2"
    },
    {
        productname: "productname3",
        category: "category3"
    },
    {
        productname: "productname4",
        category: "category1"
    },
    {
        productname: "productname5",
        category: "category2"
    }
]

I want to get an output where I can get all the categories without having duplicates

I tried using map and filter but my output was:

["category1" "category2", "category3","category1","category2"]

my desired output is

["category1" "category2", "category3"]

How can I achieve this?

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

0

You can use map to extract the category property values and Set with spread syntax to get the unique:

const array = [{
    productname: "productname1",
    category: "category1"
  },
  {
    productname: "productname2",
    category: "category2"
  },
  {
    productname: "productname3",
    category: "category3"
  },
  {
    productname: "productname4",
    category: "category1"
  },
  {
    productname: "productname5",
    category: "category2"
  }
]

const uniqueCategories = [...new Set(array.map(e => e.category))]
console.log(uniqueCategories)

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!