Discussions
Categories
Groups
Advertisement
Child Item
Home
Topics
Technology & Internet
Software & Web Development
Development
Comparison Operators in Javascript
Trampas
Hi,
Can you have a like command in javascript i.e.
If (x like '%HelloWorld%)
{
then do this
}
else
{
do this
}
I can't find it anywhere
All i can find is == , != , === and the <> but not like.
Please help
Find more posts tagged with
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of
Advertisement
Advertisement
Comments
Hobbes
!= would be the same as <>
seamus
Google for regular expressions. Javascript implements regular expressions for pattern matching. The Like operator is an SQL operator.
Cake Fiend
Or you could lever whatever is java's standard does_string_contain_this_string( string1 , string2 ) function to do it - strstr() or whatever for a quick and dirty fix.
cgarvey
Something like the following should work:
if( x && x.substring( 'HelloWorld' ) > -1 ) { // then do this } else { // do this }