thArr = (v for k, v of things)
How do I extract values from a Coffeescript associative array (ie hash) into a simple array?
-
21-06-2023 - |
質問
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.
解決
他のヒント
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
所属していません StackOverflow