如何从退货中获取数据

我的函数返回我下面的数据,

how can i get from this data for example country?

[ { latitude: 52.6997543,
    longitude: 15.2602551,
    country: 'Poland',
    city: 'Gorzów Wielkopolski',
    state: 'Lubusz Voivodeship',
    zipcode: '66-446',
    streetName: 'Zieleniecka',
    streetNumber: '4',
    countryCode: 'pl',
    county: 'Gorzów Wielkopolski',
    extra: { confidence: 10, confidenceKM: 0.25 },
    provider: 'opencage' } ]

这是我的功能:

fn: async function({address, country, zipCode}){
        // const location = address + ' ' + city
        const response = await geocoder.geocode({
            address: address,
            country: country,
            zipcode: zipCode,
            minConfidence: 0.5,
            limit: 1
        })
        return response
    }
评论
  • WOW
    WOW 回复

    由于您的数据是列表中包含的对象,因此您可以访问country属性,如下所示:

    var list = [ { latitude: 52.6997543,
        longitude: 15.2602551,
        country: 'Poland',
        city: 'Gorzów Wielkopolski',
        state: 'Lubusz Voivodeship',
        zipcode: '66-446',
        streetName: 'Zieleniecka',
        streetNumber: '4',
        countryCode: 'pl',
        county: 'Gorzów Wielkopolski',
        extra: { confidence: 10, confidenceKM: 0.25 },
        provider: 'opencage' } ];
        
    console.log(list[0].country);