Is there a way to modify this for loop so that it runs through the entire array instead of adding one by one?
Any suggestions?
EndorsedSkillSchema.methods = {
async userEndorsedSkill(arr) {
for (var i = 0; i < arr.length; i++) {
const skill = await Skill.findOne({ _id: arr[i]._id });
const s = skill.toJSON();
this.skills.push(arr[i]._id);
await this.save();
pubsub.publish(SKILL_ENDORSED, { [SKILL_ENDORSED]: { ...s } });
return {
endorsed: true,
...s
};
}
}
};