Reputation: 8379
I have a situation where I have to setup a conditional to detect IE8. I would like to convert the below process...
if(['About', 'Join', 'Participate','Support','Media Center','Error 404'].indexOf(msubpagetitle) == -1) {
//do custom jquery actions
}
...to a jQuery.inArray() condition. How do I do this?
Upvotes: 0
Views: 47
Reputation: 2510
if($.inArray( msubpagetitle,['About', 'Join', 'Participate','Support','Media Center','Error 404'])!=-1);
The $.inArray() method is similar to JavaScript's native .indexOf() method in that it returns -1 when it doesn't find a match. If the first element within the array matches value, $.inArray() returns 0.
Because JavaScript treats 0 as loosely equal to false (i.e. 0 == false, but 0 !== false), to check for the presence of value within array, you need to check if it's not equal to (or greater than) -1.
Upvotes: 1