I have this piece of code that runs a simple for loop:
const InvType = ["Hat", "Face", "FaceAccessory", "HairAccessory", "BackAccessory", "NeckAccessory", "FrontAccessory", "WaistAccessory", "Gear"]
var Prom = new Promise((resolve, reject) => {
var Inv = []
for (var i = 0; i < InvType.length; i++) {
https.get('https://inventory.roblox.com/v1/users/111138402/assets/collectibles?assetType=' + InvType[i] + '&sortOrder=Asc&limit=100', (resp) => {
let data = '';
// A chunk of data has been received.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
var arrayLength = JSON.parse(data).data.length;
for (var v = 0; v < arrayLength; v++) {
Inv.concat(JSON.parse(data).data[v])
console.log(i)
}
if (i >= 9) {
resolve(Inv)
}
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
}
})
I would like for this to resolve the promise once the Inv table has been filled, that way I do not move onto the next step of the code before the required data has been gathered.
for some reason the "i" variable in this loop always prints out as 9, and so the promise is resolved before anything is even put into the table. I am not the best at node, and do not know why this would be happening.