Currently, I am attempting to retrieve a specific field within a nested array using the following code:
var array1 = [];
const data = { [userId]: [{
id: id,
name: fullName,
email: userEmail },
],
};
array1.push(data);
After printing this using
console.log("index 0: ", array1[0]);
, the output is:
index 0: {
buMqSZpEaKZABffDGNs5jzVK36Y2: [
{
id: '65',
name: 'nameTest',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aec3d7cbd6c3cfc7c2eec9c3cfc7c280cdc1c3">[email protected]</a>'
}
]
}
However, I am trying to figure out how to access the information within the userId, such as userId.name and locate a specific userId like "aePoUZpkUnlAOMNBGNs5ynMD36L1" in array1 to display its details similar to activeSockets[0].
or using indexOf()
. Whenever I attempt to access the fields inside, it often results in a
Cannot read property '' of undefined
error. Any guidance on this issue would be highly appreciated.