I am currently facing an issue while attempting to iterate through data retrieved from an API request. The structure of the data is as follows:
[ { kind: 'qpxexpress#tripOption',
saleTotal: 'USD107.70',
id: 'fANabOjuLoDMb9zppwbeXL002',
slice: [ [Object] ],
pricing: [ [Object] ] },
{ kind: 'qpxexpress#tripOption',
saleTotal: 'USD107.70',
id: 'fANabOjuLoDMb9zppwbeXL003',
slice: [ [Object] ],
pricing: [ [Object] ] },
{ kind: 'qpxexpress#tripOption',
saleTotal: 'USD107.70',
id: 'fANabOjuLoDMb9zppwbeXL001',
slice: [ [Object] ],
pricing: [ [Object] ] } ]
My for loop implementation seems to be causing a type error during execution. I'm finding it challenging to troubleshoot this issue. Can you help identify what might be missing in my code?
request(options)
.then(function (response) {
//.log(response.trips.tripOption)
let selects = 0
for(let i = 0; i < response.trips.tripOption.length; i++) {
if (response.trips.tripOption[i].selected) {
selects++
}
}
return selects;
console.log('hello' + ' ' + selects);
})
.catch(function (err) {
console.log(err);
});