简体   繁体   中英

API calls for each element on array ( React )

I'm trying to make an API call for each element on the array and I tried:

let requests = array.map(elem=> {
        return new Promise((resolve, reject) => {
           API.update(elem).then(data => data);
        })
     })
     Promise.all(requests);

but I see in the network the (elem) is undefined and I don't recognize why this happned.

Can you post the full context of your code so we can see the array that you're mapping over?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM