i need some solutions. Here is my situation; i want to get the value of an array's item within an object using the "KEY". For example, i have this object:
const obj = {
id: 1,
fields: [
{id: 1, name: 'test'},
{id: 2, name: 'test2'},
]
}
and i want to get name's value of the first element in fields. So the solution i know is that we can do: obj['fields'][0]['name']
... but what i'm looking for is just doing something like obj[KEY]
.
So the question is: is that possible and what kind of KEY i can use to do it ?