JavaScript | Check if a variable contains another

I keep needing some way in JavaScript to check if a variable contains another.
Guess I'll just post it for future necessities.


 function custom_contains(str_full, str_partial)
 {
     var new_full = str_full.toString().toLowerCase();
     if(new_full.indexOf(str_partial) !== -1)
     {
         return true;
     }
     return false;
 }

usage:
if(custom_contains("my string", "my"))
{
//true, do something
}
else
{
//false, do something
}

Comments

Popular posts from this blog

Breaking down document locking in SharePoint

Working around X-Frame-Options for iframes

Document ID not being generated