Case Insensitive for Includes Function

Hi there!
I have a search function that uses the includes function but it is case sensitive. Can anybody help me how to make this case insensitive? Below is my code:

import {getAllRecords} from ‘backend/dataService’;
// Backend module named dataService.jsw under backend folder

let unfilteredRecords = ; // This will hold all records

$w.onReady( function () {
$w(“#repeater1”).data = ; // Clear repeater from data
getAllRecords().then((allObjects) => {
unfilteredRecords = allObjects;
// Store all records in array
$w(“#repeater1”).data = unfilteredRecords;
// Set all records to repeater
})
});

// Search button onClick event
export async function searchButton_click(event) {
let searchWord = $w(“#searchInput”).value;
$w(“#repeater1”).data = unfilteredRecords.filter(obj => obj.occasion.includes(searchWord)); // name is fieldKey is Data Collection
}

Big thanks to https://uggadugg.wixanswers.com/en/article/search-faster-using-filter-function for the search code.

Hi Freed ,

You can add a Regex that ignore case sensitivity. Go to the element ( input settings ), if you scroll all the way down you’ll find add pattern validation . Check out this discussion about creating - Regex: ignore case sensitive -

Hope this helps!
Best,

Mustafa

Just change the line

$w("#repeater1").data = unfilteredRecords.filter(obj => obj.occasion.includes(searchWord)); // 

to

$w("#repeater1").data = unfilteredRecords.filter(obj => obj.occasion.toLowerCase().includes(searchWord.toLowerCase())); 

I have just added the use of the function .toLowerCase()
You may want to also check for null references, as below

$w("#repeater1").data = unfilteredRecords.filter(obj => (obj.occasion?obj.occasion.toLowerCase().includes((searchWord?searchWord.toLowerCase():searchWord))):false); 

It works like a charm! Are you a wizard? Thank you so much.

@mhammouz is this also possible with Corvid Wixdata.query?