Hi all.
I am trying to extract of all the individual IDs in a collection, to use elsewhere to process the content of the collection.
Here’s my current code:
import wixData from 'wix-data';
$w.onReady( async function() {
let results = await bigQuery();
var item_Id_list = [];
console.log(results);
console.log(results.items[1]._id);
for (var i=0;i<10;i++) {
item_Id_list[i] = results.items[i]._id;
}
console.log(item_Id_list);
})
async function bigQuery(){
for (var i=0;i<10;i++) {
let results = wixData.query("BookReviews")
.find();
return results;
}
}
The first console.log gives me the expected object and the second gives me the ID that I was after, from the second item in the collection (added this laterm in an effort to understand why I can’t build the array.
When I run the for loop, I get the following error:
Why doesn’t this work? Can’t see how its a timing issue, as the results is appearing in the console as you’d expect and I have the await function there on the query. So maybe I am just trying to read the object wrong??
Haven’t done this before and have been reading to try to figure it out but to no avail…any help would be appreciated!