DEV Community

Kunal Vijan
Kunal Vijan

Posted on

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

I wanted to show only 1 record among the DL list which has a minimum score from all the DLs. Currently it's displaying all the records.

In the example on stackblitz you can see for the first record DL scores are : 54, 20 and updated.

I want Instead of showing all 3 records I wanted to display only 1 record which has least score i.e. 20.

Please suggest.

Live https://stackblitz.com/edit/angular-ivy-1tsz1r?file=src%2Fapp%2Fapp.component.html

Top comments (1)

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! 😊