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

192
Views
How to filter API category in React

That's my JSON:

{
"_id": "61d18b98d489dfcff325843d",
"productName": "Cantilever chair",
"productImg": "https://i.ibb.co/k5hNxd3/image-1168.png",
"price": 42,
"productCode": "Y101",
"category": "featured",
"review": 4,
"totalReview": 42,
"Color": "White",
"description": "LumbarSupport Office Chair Meeting chair designed with curved contour giving optimalsupport to your lumbar and keep your spine aligned properly. Ergonomicreclining lean back design makes it extremely comfort.CoolingMesh Back & Extra Comfort Cushion Added comfort with breathable fabric that you can relax into, added high density mesh-covered foam seat cushion forextra comfort. Embrace a pain free working day.Office ChairDesign in Style Well design in front of an office desk, reception room oraround conference table. Offers professional appearance in any office setting,making it easy for colleagues and clients to have a seat with our desk chair.EasyAssemble You just need to tighten the screws then you will get an aestheticoffice chair. Tips on assemble: leave the chair back slack till all screwsaligned then tighten"
},

How can I filter it and only get the products which have catogery featured?

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

0

Use the array filter method.

your_array.filter(item => item['category'] === "featured");

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

This has nothing to do with react by the way. It's vanilla javascript.

about 4 years ago · Juan Pablo Isaza Report

0

You can use the filter method.

const items = [
  {
    _id: "61d18b98d489dfcff325843d",
    productName: "Cantilever chair",
    productImg: "https://i.ibb.co/k5hNxd3/image-1168.png",
    price: 42,
    productCode: "Y101",
    category: "featured",
    review: 4,
    totalReview: 42,
    Color: "White",
  },
  {
    _id: "61d18b98d489dfcff325843d",
    productName: "Cantilever chair",
    productImg: "https://i.ibb.co/k5hNxd3/image-1168.png",
    price: 42,
    productCode: "Y101",
    category: "something",
    review: 4,
    totalReview: 42,
    Color: "White",
  },
];

const filteredItems = items.filter((item) => item.category === "featured");
console.log("filteredItems", filteredItems);
about 4 years ago · Juan Pablo Isaza Report

0

There are many ways to do this. Here, I have two major ways to solve this:

  1. using filter:

    array.filter(data => data.category === "featured")
    
  2. using find:

    array.find(data => data.category === "featured")
    

The major difference is that the Filter method will return the array object. i.e [{_uId: ...}] Whereas, Find method will return the object only. i.e {_uId:...}

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!