coffeescript Arrays Filtering values

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

theUsers = [
  {id: 1, username: 'john'}
  {id: 2, username: 'lexy'}
  {id: 3, username: 'pete'}
]

To retain only users whose id is greather than 2, use the following:

[{id: 3, username: 'pete'}]

Method 1 - using .filter

filteredUsers = theUsers.filter (user) -> user.id >= 2

Method 2 - using comprehension

filteredUsers = (user for user in theUsers when user.id >= 2)


Got any coffeescript Question?