Hi I am trying to combine the results of my axios get request into one array.
I am grabbing data from Mongoose and MongoDB database which returns me an array of relevant information for the axios request to run through
I run the info through axios.get and it returns me with respective results for each object in the array
See below
const axios = require("axios");var info = [500000, 2020, 12341234, 12341234]
var algo = “cn8”console.log(info)
for (var i = 0; i < info.length; i++){
var url = "https://whattomine.com/coins.json?" + algo + “=true” + “&factor%5B” + algo + “_hr%5D=” + info[i]
axios.get(url)
.then((response) => {
var result = response.data.coins.Monero.btc_revenueconsole.log(result) })
}
However I am also trying to write this result back into my MongoDB/Mongoose database for further logging and someone suggested I can use the map function to run the write functions going back into the database for it.
However map only works for arrays and the results I am getting from axios are not. Does anyone have any idea how to join these response I am getting into one array?
I have attached a picture below for reference
Keep in mind these are the results for console.log(info) is in GREEN for data going in
console.log(result) is in RED for data supposed to be going out (need to transform into combined array first, not sure how to do when all the results are in one variable)
#javascript #arrays #mongodb