Putting array into table

Hello,
I made a collection called “batteries” which contains lots of columns. I would like to make a table which will contain unique values from one of “batteries” collection columns.

So i wrote a code:


$w.onReady(function () {
    wixData.query('Batteries')
 .find() 
 .then(results => {
        console.log(results.items);
 let markers = [];
 for (let i = 0; i < results.items.length; i++) {
 let loc = results.items[i];
            markers.push({type: loc.type});
 }
 function getUniqueTitles(items) {
 const titlesOnly = items.map(item => item.type);
 return [...new Set(titlesOnly)];
 }
 let nowy = getUniqueTitles(markers);
        console.log(nowy);
$w("#table3").rows=nowy;
 });
});

I have in array “nowy” all values that I would like to put into “table3”.
How can I do that? $w(“#table3”).rows is giving me an error:

Wix code SDK error: The row parameter of item at index 0 that is passed  to the rows method cannot be set to the value Li-Po. It must be of type  object

“li-po” is a value from “nowy” array.

Regards

Tables expect an array of objects, and you’re feeding it a one-dimensional array. All there is in that row is the value “li-po”. Instead, it needs to be an object.

You might consider using the distinct function in the query. The function returns a one dimensional array. Then, do the for loop on that to create an object array like what you’re doing. You wouldn’t need to use the getUniqueTitles function.

Sometimes you may need to have a replacement code if something do not work like expected…

Anyway, surely anthonyb is right and using distinct the is better way to go, but on my opinion not a must.
Found an old post of myself about distinct here, perhaps it can help you understanding —> distinct, better.
https://russian-dima.wixsite.com/meinewebsite/test-test-test

And here an little example of a DropDown-Distinct…

var DDprefix = "DD" ; //setup-8 -----> DropDown-Prefix (DropDown-Element-ID)
DropDowns[0] = "insert --->DATAFIELD-ID-1 here for this DROPDOWN"
DropDowns[1] = "insert --->DATAFIELD-ID-2 here for this DROPDOWN"
DropDowns[2] = "insert --->DATAFIELD-ID-3 here for this DROPDOWN"

//------------------[ Create - Dropdowns ] ----------------------
async function create_DropDowns(dbDATA) {console.log("LOAD DropDowns")
  let Options = []
  for (var a = 0; a < DropDowns.length; a++) {
    if(DropDowns[a]) {await dbDATA.distinct(DropDowns[a])
      .then((results) => {let items = results.items
          if (items.length > 0) {
            for (var b = 0; b <items.length; b++) {
                Options.push([]) 
                Options[a].push({"label": items[b], "value": items[b]})
            }
            $w('#'+DDprefix+(a+1)).options = Options[a]
            $w('#'+DDprefix+(a+1)).placeholder = DropDowns[a]
          }
          else{ } 
       })
    } 
  }
}