I am trying to string multiple fetches while also performing a promise on each of them. My goal is after every fetch is 1. to parse the data retrieved and 2. append it to an object as demonstrated by each.scripture = data
. After this procedure is performed on each url, I want to 3. resolve the now changed data
that was originally passed into the function header. Can someone please assist me with this? As you can see I have attempted this, but this does not work as intended.
function getScripture(data) {
var feed = []
return new Promise((resolve, reject)=> {
data.map((each)=> {
fetch(`https://getbible.net/json?passage=${each.book}${each.chapter}:${each.verse}&version=web`, {
'method': 'GET',
'headers': {
'Content-Type': 'application/json'
}
})
.then((response) => response.text())
.then((data) => {
data = JSON.parse(data.substring(1,data.length - 2))
data = data['book'][0]['chapter'][each.verse.toString()]['verse']
each.scripture = data
feed.concat(each)
})
.catch((err)=> reject(err))
})
resolve(feed)
})
}