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

193
Views
Displaying a nested data with a conditional: How can I not display the data whose product's color is not according to the conditional?

I am trying to display all the quantity of colors that are more than 10. It does display it, however, this will also display even the products whose colors are less than 10. How do I fix this? Thank you.

codesandbox: https://codesandbox.io/s/products-0ccdhk?file=/src/App.js:752-1189

 {product &&
        product.map((item, i) => (
          <ul key={i}>
            <li>{item.id}</li>
            <li>{item.prodName + " " + item.size}</li>
            {Object.entries(item.colorMap).map((color) => (
              <>
                {color[1] > 10 && (
                  <>
                    {color[0]} - {color[1]}
                  </>
                )}
              </>
            ))}
          </ul>
        ))}

Currently, this is what it looks like:

enter image description here

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

0

{product &&
    product.map((item, i) => {
      const obj = item.colorMap;
      for (let x in obj) {
        if (obj[x] > 10) {
          return <li key={i}>{item.prodName + " " + item.size}</li>;
        }
      }
    })}

Link CodeSandbox: https://codesandbox.io/s/products-forked-mtt94c?file=/src/App.js:752-1008

Because you used "=> ()" in map method, it returned whole items in your product array. I replaced it as "=> {}" and returned with a condition in "{}".

You can also write like this:

export default function App() {

  const newProduct = product.filter((item) => {
    return Object.values(item.colorMap).every((color) => color > 10);
  });

  return (
    <ul className="App">
      {newProduct &&
        newProduct.map((item, i) => (
          <li key={i}>{item.prodName + " " + item.size}</li>
        ))}
    </ul>
  );
}
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!