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
}
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
Post a Comment