Mongoose for var in loop in subdocuments Mongoose for var in loop in subdocuments mongoose mongoose

Mongoose for var in loop in subdocuments


Use an indexed for loop, instead of a forin:

for (let i = 0; i < socialAccounts.length; i++) {    var currentAccount = socialAccounts[i];}

The forin loop will enumerate additional object properties as you noticed and should not be used for arrays. See this question and answers.