[英]no-return-assign - when to disable
I am trying to pass ids in this object array: 我正在尝试在此对象数组中传递ID:
const children = [{name: Jack, age: 8}, {name: Joe, age: 6}];
children.forEach((child) => (child.id = v4()));
I keep getting eslint error no-return-assign
this is really bugging me (pun intended) 我不断收到eslint error no-return-assign
这确实让我烦恼(双关语)
I tried: 我试过了:
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()
});
None work. 没有工作。
Should I disable eslint? 我应该禁用eslint吗? Is there a workaround? 有解决方法吗?
Well don't return anything from your callback function. 好吧,不要从回调函数返回任何东西。 Just write 写吧
children.forEach(child => {
child.id = v4();
});
or even simpler 甚至更简单
for (const child of children) {
child.id = v4();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.