Javascript Mistake — 1

Nadtakan Futhoem
1 min readSep 24, 2019
users[index].emailVerified = cognitoUser.UserAttributes[1].Value;

UserAttributes[1] — to avoid mistake you should not specific index and code should look like this.

Object.keys(cognitoUser.UserAttributes).forEach((index) => {
// assigning cognitoUser.UserAttributes[1].Value
if(cognitoUser.UserAttributes[index].Name === 'email_verified'){
users[index].emailVerified = cognitoUser.UserAttributes[index].Value;
}
});

Using object.key looping through the array and look for which JSON field you want.

--

--