Collecting table info adding columns and saving into json entry

Hey sorry for the lack fo experience,

I have a table called table1 that is populated from a wix collection. Which is first filter based on user input and the displayed as an order overview. Uppon pressing a button I want to create a json which contains different user inputs (this i can do) but also the list containing the elements within one column of the filtered table1. And i want to save this json entry as a “row” in a wixcollection.

I dont know how to aproach this and if it is even possible.

Appreciate all the help and info!

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 )];
}