ReactJS axios.post inside a map through array function that returns an object

You can use Promise.all

async function() {
  const promises = paramArray.map(paramKey => axios.post(URL, {
      filters: [
        {
          field: "key", 
          values: [paramKey.key]
        }
      ]
    })
  );

  const values = await Promise.all(promises)
  const finalArray = paramArray.map((paramKey, index) => {
    return {
      key: paramKey.key,
      text: values[index].data.itemName,
      value: paramKey.value
    }
  })
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top