uploadUsernames(){
let currentUser = firebase.auth().currentUser
db.collection('users').where('user_id',"==", currentUser.uid).get().then(snap => {
snap.forEach((document) =>{
for(let counter=0; counter<=this.usernames.length; counter++){
db.collection('users').doc(document.id).update({
name: this.name,
bio: this.bio,
usernamelist:[{Id:counter, username: this.usernames[counter]}]
})}
})
}).then(() =>{
this.$router.push({ name: "Profile" })
})
I have a list of usernames stored in the 'usernames[]' array that I intend to save into my user documents. Each element's index corresponds to the 'Id' of every item within the Firestore document 'users', located in the 'usernamelist' field named 'username' at the matching 'Id'. How can I iterate through each array item and update the appropriate entry in Firestore? A message stating that 'i' is undefined is being returned as an error.