Dav*_*Sag 96 arrays append coffeescript
在CoffeeScript中将值附加到数组的规定方法是什么?我检查了PragProg CoffeeScript书,但它只讨论了创建,切片和拼接,以及迭代,但没有附加.
Thi*_*ilo 189
好老push还在用.
x = []
x.push 'a'
Run Code Online (Sandbox Code Playgroud)
sur*_*ami 49
更好的是使用列表推导.
例如而不是:
things = []
for x in list
things.push x.color
Run Code Online (Sandbox Code Playgroud)
改为:
things = (x.color for x in list)
Run Code Online (Sandbox Code Playgroud)