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 to filter the products that are only in Stock? (ReactJS)

I am trying to filter the products that are only inStock: true, I do not know how to insert it on this code:

enter image description here

The products are showing even the inStock is false. Here is how my products look like:

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

enter image description here

>Solution :

If you want to filter the items depending on the value of inStock you should use .filter() like so:

products.filter(product => product.inStock === true)

Here product represents an element of products, which in your case is an object, and like any object you can access the properties inside using the dot accessor ‘.’

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