I’m trying to run a simple loop to pull in some images to a collection from URLs
I am pulling 10 results from a collection and assigning them to the review variable. This works fine. I then want to pull each record in the collection in turn using a while loop. I had the code written for that, which I understand, but I cannot get the loop to see the review variable…is there something I need to do to pass the variable to the loop? I pulled the other code out to see if I could just log the variable in the console.
The first two console.logs work fine. The third just outputs "Array to process: [object Object] " in the console.
import wixData from 'wix-data';
$w.onReady( async function() {
let reviews;
await wixData.query("Books")
.limit(10)
.find()
.then((results)=> {
reviews = results.items;
})
console.log(reviews)
console.log(reviews[0])
let i = 0;
while (i < 5) {
console.log("Array to process: "+reviews[i]);
i++;
}
})
Haven’t done a lot with loops until now, so haven’t see this before…sorry if it seems like a total noob question…
Simon.