Collecting table info adding columns and saving into json entry

If you are using the wix data api, you can simply take the results.items and map them in a new function and return the unique field values of your choice. I use this dynamic function all the time to map one value from array for all repeater items.

function getUniqueFieldValues ( items , title ) {
const fieldValuesOnly = items . map ( item => item[title ]);
return [ … new Set ( fieldValuesOnly )];
}

An example would be like this:

async function test () {
wixData . query ( ‘YearlyBudget’ )
. descending ( ‘year’ )
. limit ( 1000 )
. find ()
. then (( res ) => {
if ( res.items.length > 0 ) {
//get unique year values onlu
let yearsOnly = getUniqueFieldValues ( res.items , ‘year’ )
console . log ( yearsOnly , ‘years only mapped’ )

            //rest of code here 
        } 
    }) 

}

function getUniqueFieldValues ( items , title ) {
const fieldValuesOnly = items . map ( item => item[title ]);
return [ … new Set ( fieldValuesOnly )];
}