使用 foreach 向项目添加新属性不起作用

问题描述

我在数组中有一个数组。

我正在尝试向第二个数组添加一个计数器。

我在数组中创建了一个属性,在 console.log 中,这个新属性 "actors_count" 显示正常。

在第二个 console.log退出循环时,该属性仍然存在。

但在我的回报中,财产消失了。

有人可以帮我吗?

var actor_weights = await ActorWeight.findAll({include: {model: Actor,as: 'actors'}});

actor_weights.forEach(element => {
    const actors_count = element.actors.length;
    element.actors_count = actors_count;
    console.log(element.actors_count);
});

console.log(actor_weights.actors_count);

return res.status(200).send({
    actor_weights
});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)