How can I reference an array when I don’t know the name of it?

In my Cloud Firestore I have a database comprised of several users, and on their structure there’s an array called contacts that has several nested arrays. The id (or name, if you will) from every single of one of those arrays is the id from another user. Like so

"contacts": [
   "UserAid": [
      "value1",
      "value2",
      "value3"
   ],
   "UserBid": [
      "value4",
      "value5"
   ]
]

The thing is, I want to delete value2 from contacts. However, the UserAid is actually a value generated at random by an UUID generator. I know that deleting a value from an array is as simple as:

firebase.firestore().collection('Users')
        .doc(user.id)
        .update({
           array: firebase.firestore.FieldValue.arrayRemove(`${valueName}`)
        })

However, because in this case “array” on the update function is a dynamic value (aka the uuid of another user), how can I reference “UserAid” on my function to delete de value?

Answer

You can use [] notation to use the value of a variable as the property name. So:

const fieldName = "theFieldNameThatYouWantToUpdate"
firebase.firestore().collection('Users')
        .doc(user.id)
        .update({
           [fieldName]: firebase.firestore.FieldValue.arrayRemove(`${valueName}`)
        })

If you don’t have the name of the field to update, you’ll have to first load the document to determine that.