Question

I have a simple associative array in Coffeescript as follows

things = 
  login: 'login/'
  search: 'search/'
  custard: 'trampoline/'

and I want to generate an array ['login/', 'search/', 'trampoline/']

Sure I could do this:

  thArr = []
  for k, v of things
    thArr.push v

but I'm sure there is a one-line way to do this, but I'm not sure how.

Was it helpful?

Solution

  thArr = (v for k, v of things)

OTHER TIPS

If you know what index the key => value are located at. e.g

arr = {a: 1, b: 2, c: 3}

Object.values(arr)[0]

result: = 1 *because a: 1 is at index 0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top