Get an array of date values from dataset, and based on the values, filter a date array, to get the ones available

@allu112apina Sorry, I found two errors in my code, I changed the datepicker element name to make it more readable, but forgot to change it in every place used, here is the corrected version:

import moment from "moment"
import wixData from "wix-data"


$w.onReady(async () => {

 //When you change the End Date Date Picker date, it queries and updates the table
  $w("#datePickerEnd").onChange(async (event) => {
 
 //This creates the search
 let searchAvailableRentals = await createSeach($w("#datePickerStart").value, $w("#datePickerEnd").value)

 //This feeds the table with the data that was searched
    feedTable($w('#tableAvailableRentals'), searchAvailableRentals)
 })

 

})

//This is a function to query the collection.
async function queryCollection(collection, field, array) {
 let query = await wixData
 .query(collection)
 .not(wixData.query(collection).hasSome(field, array))
 .find()
 .then(result => result)
 return query
}

//This function creates the Date Array
function createDateArray(start, end) {
 let dateArray = []
  start = moment(start)
  end = moment(end)
 while (start <= end) {
    dateArray.push(start.format("YYYY-MM-DD"))
    start = moment(start).add(1, "days")
 }
 return dateArray
}


//This function feeds the table with the data
function feedTable(table, data) {
  data.forEach((element, index) => {
    element.rowNumber = index + 1
 })
  table.rows = data
 const tableColumns = [
 {
      id: "col1",
      dataPath: "rowNumber",
      label: "Number",
      width: 30,
      visible: true,
      type: "string",
 },
 {
      id: "col2",
      dataPath: "_id",
      label: "ID",
      width: 100,
      visible: true,
      type: "string",
 },
 {
      id: "col3",
      dataPath: "title",
      label: "Title",
      width: 100,
      visible: true,
      type: "string",
 },
 ]
  table.columns = tableColumns
}

//This function does the search and treats it
async function createSeach(startDate, endDate) {
 let rentalDates = createDateArray(startDate, endDate)
 let search = await queryCollection("Rentals", "rentedDates", rentalDates)
 if (search.items.length > 0) {
 return search.items
 }
 return "No rental available!"
}