coffeescript Arrays Mapping values


You want to convert all elements in an array to some other form.

For example, you have

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

and you want to have an array of usernames only, i.e.

['john', 'lexy', 'pete']

Method 1 - using .map

theUsernames = (user) -> user.username

Method 2 - using comprehension

theUsernames = (user.username for user in theUsers)