Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I output the product name, the color and its color quantity that is less than 10 as a list?

This is the following data from the Firebase. Take note that some of the products have 1, 2 or 3 colours in each products. I want the color and the color quantity that is less than 10 to output

his is the output of the code. This is what I want it to look like. But in the output as you can see the colour is too close to the quantity and that the product Tumbler it outputted a colour that is not less than 10.

This is the code that I’m having trouble with.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    <ul>
    {details.filter((detail) => Object.values(detail.colorMap).find(c => c < 10)).map((val) => 
    {
    return (<li key={val.id}><p className="pt-2">{val.prodName}{Object.entries(val.colorMap).map((c) => (<p>{c[0]}{c[1]}</p>))}</p></li>);
    })}
    </ul>

>Solution :

You can add another filter() to get colours with value less than 10 only as shown below:

<p className="pt-2">
  {val.prodName}
  {Object.entries(val.colorMap)
    // Filter for colors with value < 10
    .filter((c) => c[1] < 10)
    .map((c) => (
      <p>
        {c[0]}
        {c[1]}
      </p>
    ))}
</p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading