so I have this json
items: [
{
id: 123
},
{
id: 456
}
]
and I am trying to get the value with javascript of the second id which has a value of 456, but I have no idea how to because it doesnt have a specified parent by which I could get it.
Your use case isn't exactly clear so the best answer I have for this is to specify the index:
const data = [
{
id: 123
},
{
id: 456
}
];
const secondId = data[1]?.id;
If you are looking for a specific id you can use the find method:
const data = [
{
id: 123
},
{
id: 456
}
];
const secondObj = data.find(a => a.id === 456);
It should also be noted that if you're hitting an API that's querying a database you can't expect that 456 will always be the second object unless the backend code is explicitly ordering it this way.