3
let data = [
  {a: 1},
  {a:2}
]
data.forEach(v => {
  v.title = "hello"
})

console.log(data) // [ {a: 1, title: "hello"}, {a:2, title: "hello"} ] 成功赋值
let data = [
  {a: 1},
  {a:2}
]
data.forEach(v => {
  v = {a:1, title: "你好"}
})

console.log(data) // [ {a: 1}, {a:2} ] 赋值失败

Correct writing:

let data = [
  {a: 1},
  {a:2}
]
data.forEach((v, i) => {
  data[i] = {a:1, title: "你好"}
})
console.log(data) // [ {a: 1, title: "你好"}, {a:1,  title: "你好"} ] 赋值成功

前端box
75 声望1 粉丝