Mongoose for var in loop in subdocuments
Use an indexed for
loop, instead of a for
… in
:
for (var i = 0; i < socialAccounts.length; i++) {
var currentAccount = socialAccounts[i];
}
The for
… in
loop will enumerate additional object properties as you noticed and should not be used for arrays. See this question and answers.