How to write if include? condition in JavaScript?
My sample code is here:
var a = ['red', 'green', 'blue', 'yellow'];
if (a.include("red" ))
{
alert(a);
}
It gives the following error:
SyntaxError: missing : in conditional expression
You can use $.inArray() in jQuery
$(function(){
var a = ['red', 'green', 'blue', 'yellow'];
if ($.inArray( "red", a )>=0)
{
alert(a);
}
});
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With