I have an array of values in Coffeescript such that:
arr = ['key1': 1, 'key2': 2, 'key3': 3]
I want to transform this array into an array of just values. Basically,
arr.map (iter) -> iter.value # arr => [1,2,3]
=> []
I’ve attempted several permutations of this, but I just keep getting back an empty array. Any tips?
This is a CoffeeScript question and the sample code is valid CoffeeScript
arr = ['key1': 1, 'key2': 2, 'key3': 3]translates to the following JavaScript:
Firstly, you have to realize that
is most likely what you want.
Then you can use the following code to create an array with only the values of the object.
Update
This one-liner from ‘mu is too short’ is even better.