0

I have an array of area code const regions = [123,12312,1231231,123123,123123]

and

I have an End Point something like https:service.org?where=id=${code}

Data that I get from response looks something like this:

features: [{data}]

Now All I am trying to do is get the response, store it in the array, and create a JSON File. Here is the snippet of the code, that I have

const getResponse = async () => {
 
    let responseData =[]
    regions.forEach(async (code)=> {
        const response = await fetch(`https://services.org?where=id=${code}`); 
        const data = await response.json();
        
        responseData.push(data.features[0])
    })

    console.log(responseData)
}

When I console.log the response data it provides me an Empty Array and I am not sure why it is behaving like this.

Sulav Dahal
  • 129
  • 3
  • 10

0 Answers0