I am trying to access a specific field inside the nested array. My code is like this:
var array1 = [];
const data = { [userId]: [{
id: id,
name: fullName,
email: userEmail },
],
};
array1.push(data);
If I print this:
console.log("index 0: ", array1[0]);
It gives this result:
index 0: {
buMqSZpEaKZABffDGNs5jzVK36Y2: [
{
id: '65',
name: 'nameTest',
email: 'myexmail@gmail.com'
}
]
}
However, I would like to know how I can access the information inside the userId, like userId.name and be able to find a specific userId. For example, in the array1 find userId "aePoUZpkUnlAOMNBGNs5ynMD36L1" and display its information as if I did like this activeSockets[0].
or indexOf()
. Most of the times I have tried accessing the fields inside it says Cannot read property '' of undefined
. Any help will appreciated