I need to print some text if the result has similar text, is there a like statement in jquery? Similar to how you use LIKE in SQL?
if (r.events[i].room = 'craig')
$('#'+r.events[i].slot).append('<br />').append('craighouse');
I need to print some text if the result has similar text, is there a like statement in jquery? Similar to how you use LIKE in SQL?
if (r.events[i].room = 'craig')
$('#'+r.events[i].slot).append('<br />').append('craighouse');
There is no LIKE
statement. However, you can search for one string within another using indexOf()
:
if (r.events[i].room.indexOf('craig') != -1) // -1 = not found
$('#'+r.events[i].slot).append('<br />').append('craighouse');
You can use indexOf
It returns -1 if no match is found.
if (r.events[i].room.toUpperCase().indexOf('craig'.toUpperCase()) != -1)
$('#'+r.events[i].slot).append('<br />').append('craighouse');
also, you can use toUpperCase if you don't want a match that depends on the case of the string.