【前端】iterable类型的 forEach方法
看三个例子:
a = [
age: 1
,
age: 2
]
a.forEach (item) ->
item.age = 0 # 有效
console.log a
# [
# age: 0
# ,
# age: 0
# ]
b = [1, 2]
b.forEach (item) ->
item = 0 # 无效
console.log b
# [1, 2]
b = [1, 2]
b.forEach (item, index, arr) ->
arr[index] = 0 # 有效
console.log b
# [1, 2]