How to refer to all results in a column of a query results?

Hi all,

Sorry if the title is a it confusing. I have a query:

if (date === "Monday") {

    wixData.query("vetOffices")
    .eq("title", v)
    .find()
    .then( (results) => {
    
        let r = results.items[0];
        let t = r.monday
        let o = r.mondayOpen;
        let c = r.mondayClose;
        let a = r.appointmentLength;

        if (t === "CLOSED") {
        
            console.log('search end')
            
        } else {
        
            wixData.query("30")
            .eq("time", o)
            .find()
            .then( (findings) => {
                let f = findings.items[0]
                var n = f.value;
                console.log(n);
                session.setItem("open", n)
            })
            
            wixData.query("30")
            .eq("time", c)
            .find()
            .then( (findings) => {
                let f = findings.items[0]
                var n = f.value;
                console.log(n)
                session.setItem("close", n)
            })

            let op = parseInt(session.getItem("open"), 10);
            let cl = parseInt(session.getItem("close"), 10);
            
            console.log(op)
            console.log(cl)
            
            wixData.query("30")
            .between("value", op, cl)
            .find()
            .then( (end) => {
            
                let e = end.items;
                console.log(e)
            })
        }
    })
}

It works perfectly and calls all of the results in database 30 for me. But, I need to make an array that consists of ALL of the results in a SINGLE column of the results at the end. I tried:

let tms = e.display;

But it doesn’t work. Is there any way to refer to the single column without having to go end.items[0] end.items[1] etc.?

Thanks in advance!

You created nesting promises (instead of chained promises) and it makes it hard to read. + it seems that some of the promises you could run in parallel using Promise.all() instead of one after the other (it can also improve the performance). Try to rearrange them and it’ll probably make it much clearer (in this way you’ll be able to do an action once all the promises has been resolved).

@jonatandor35 Thanks for the tip! I will definitely work towards that; however, im still not sure how to read the single column I need from the database query results, which is kind of independent of the promise.all().

I guess the idea of the function at all is to first find the opening time of a business and then its closing time (which correspond to a “time” column in the “30” dataset), and then to take all of the times in between using the “value” column of the “30” dataset. This works perfectly. The next step is displaying this information in a repeater. In order to do so, I have a third column in the “30” dataset called “display”. When I get the results from the third query, it has information from all three columns. When I refer to it like this:

end.items[0].display

it will properly return the value from the “display” column of the result. This is great; however, I need to create an array of all of the “display” column values from the result. Is there a way to do that simply or should I just create a loop with end.items[i].display and then do an arr.push?