I'm encountering an issue with GraphQL while attempting to retrieve the name of an airport from JSON data. Instead of receiving a single item containing just the airport name, I'm getting an array with additional details like city, country, geolocation, and more. Below is the code I am using...
const getNameOfAirport = (name:any)=>{
return AIRPORTS.filter((i)=>{
if(i.iata_code === name){
return i.name.length;
}
})
}
When running console.log(getNameOfAirport("BLR")), the output includes:
[
{
name: 'Bangalore',
city: 'Bangalore',
country: 'India',
iata_code: 'BLR',
_geoloc: { lat: 12.949986, lng: 77.668206 },
links_count: 195,
objectID: '3131'
}
]
My desired response is simply "Bangalore". Any assistance on this matter would be greatly appreciated. Please advise me on where I may have made an error.
Additional Note: I am utilizing TypeScript. It functions correctly with JSX as anticipated, but seems to be behaving incorrectly with TS.