Actually I am using Rapid API for my college project and want to display the flights tickets according the given departure date and return date. The response is something like this the response results image I just want to display the purchaseLinks array information, basically I want to map both the flights and purchaseLinks array every purchaseLinks has got 17 keys
I would mostly wrap all the info in a bootstrap card for good UI
I know this is wrong but I just tried doing this
fetch(mainUrl, options)
.then(response => response.json())
.then(response => {
const res = response.data.flights.purchaseLinks.map(e => e.commerceName);
console.log(res);
//console.log(response.data.flights[0].purchaseLinks[0].commerceName)
})
I tried console logging just the first one it was pretty simple to do but just like that I want to do for all the info in the given result json. I am really stuck out here is there any possible way to do this ? If yes please guide your fellow junior
Thank you 🙂
2
Answers
if you need 2d array and
for 1d
If
purchaseLinks
array will always contains a single object. In that case you can simply apply the .map method onflights
array and then access thepurchaseLinks
array object usingzero
index.Live Demo :
If purchaseLinks contains multiple objects, Then you can use two
map
to get all thecommerceName
.Live Demo :