I have an Array of Nested Objects which I'm presently mapping to get back an Array of Objects. But Instead of getting actual objects, Part of my expected result is returning an Undefined. I don't know why undefined is part of my result. I actually need to know why Undefined is part of my result. Someone to please tell me what I'm doing wrong. Thanks
My Code below
const data = [
{
"US":
{
"listed": "2022-05-25",
"address": "Kingston road, New York",
"distance": "37.3 km",
"contact": {
"email": "abc@gmail.com"
},
}
},
{
"NG":
{
"listed": "2022-05-26",
"address": "road 1, Lagos",
"distance": "12.3 km",
"contact": {
"email": "def@gmail.com"
},
}
},
];
console.log(data.map((x, i)=>{
return (
x.US, x.NG )
}))
// OutPut Here below
// [
// undefined,
// {
// listed: '2022-05-26',
// address: 'road 1, Lagos',
// distance: '12.3 km',
// contact: { email: 'def@gmail.com' }
// }
// ]
// Instead of
// [
// {
// "listed": "2022-05-25",
// "address": "Kingston road, New York",
// "distance": "37.3 km",
// "contact": {
// "email": "abc@gmail.com"
// },
// },
// {
// listed: '2022-05-26',
// address: 'road 1, Lagos',
// distance: '12.3 km',
// contact: { email: 'def@gmail.com' }
// }
// ]