What is an alternative to .hasSome() and .contains() using if-statement.

I have queried my dataset in the backend, which means I have stored my query in an array in the Page Code.
As a result, I am now struggling to add a simple Search filter. The search doesn’t use a query, but rather an if-statement. The search filter works, but only for exact searches. How do I get it to search part of a word and not be case sensitive using an if-statement?

Here is my code:

function searchResults(){

let search = $w('#searchInput').value;

if(search && search !== $w('#searchInput').placeholder) {   
              
        var filteredSearch = originalRows.filter(item => item.fullName === "*" + search + "*"); //originalRows is the array containing my query items
    }

}

how does .includes work for you? if ( search.includes( $w ( ‘#searchInput’ ). placeholder)) {
Is case sensitive, so maybe if it is allowable force your values to lowercase.

let a = “Hello” . toLowerCase ()
console . log ( a . includes ( “hello” ))

Hi Greek coder,

Like Kyle suggested use .toLowercase()

And you had somethign wrong in your code.
if( search && search
2x search?
I removed it and changed your code.

if(search.toLowercase()!==($w('#searchInput').placeholder).toLowercase())
{
var filteredSearch = originalRows.filter(item=>item.fullName==="*"+search+"*");
//originalRows is the array containing my query items
}

Kind regards,
kristof.

Hey Kyle,
I may not have been clear in my above explanation. So the text inside the If-statement is not the problem.

if(search && search !== $w('#searchInput').placeholder)

The above is fine as it is checking that “if search has text in it (ie. not empty) and if search does not equal the search Input placeholder, then go ahead into the next part”.

The issue is with:

var filteredSearch = originalRows.filter(item => item.fullName === "*" + search +"*");

where I am trying to filter originalRows and on the basis that item.fullName is equal to search (with part of the word and also not case sensitive).

[SOLVED] I made the search work with:

var filteredSearch = originalRows.filter(item => item.fullName.toLowerCase().includes(search));

Thank you for your help!

Hi Kristof,
Thank you for the response. I responded with the solution above on Kyle’s comment.

The issue was inside the THEN logic.

Thank you for the feedback!

@kscholiadis No worries.

You can also use the .toLowerCase() method to the search input, that way it becomes truly case insensitive:

let filteredSearch = originalRows.filter(item => item.fullName.toLowerCase().includes(search.toLowerCase()))

Ah yes you are correct. If I type Caps when the name is lower case then it won’t find it. I will fix that! Thank you Bruno!