DEV Community

Discussion on: How can I show only 1 record which has a least score among all?

Collapse
 
theonejonahgold profile image
Jonah Meijers

I would suggest, as you also have inputs which are going to filter the output, to filter the array with Array.filter: developer.mozilla.org/nl/docs/Web/....

If you were to implement something like this, it would look like:

const filteredUsers = users
  .filter(user => user.score > minimumScore) // where minimumScore is 20 in your case
Enter fullscreen mode Exit fullscreen mode

You can also chain the .filter method, so you can put in a filter for all your input fields:

const filteredUsers = users
  .filter(user => user.score >= minimumScore)
  .filter(user => user.gender === gender)
Enter fullscreen mode Exit fullscreen mode

Hope this helps! 😊