我正在尝试在此对象数组中传递id:
const children = [{name: Jack, age: 8}, {name: Joe, age: 6}];
children.forEach((child) => (child.id = v4()));
我一直得到eslint错误no-return-assign
这真是让我烦恼(双关语)
我试过了:
children.forEach(child => child.id = v4());
children.forEach((child) => (child.id = v4()));
children.forEach(child => (child.id = v4()));
children.forEach((child) => {
return child.id = v4()
});
没有工作。
我应该禁用eslint吗?有解决方法吗?
答案 0 :(得分:0)
不要从回调函数中返回任何内容。只需写下
children.forEach(child => {
child.id = v4();
});
甚至更简单
for (const child of children) {
child.id = v4();
}