javascript function for php in_array() like non numeric Index
i want a function for javascript like in_array in PHP to look for the special characters in an array. if t开发者_开发百科hat special character is in the array it returns true.
There is a javascript function indexOf
var myArray = [9, 3, 4, 7];
var index = myArray.indexOf(4);
// index is 2
index = myArray.indexOf(6);
// index is -1
If you use jQuery, maybe this plugin will help:
http://api.jquery.com/jQuery.inArray/
You can resort to indexOf if you (the client you are serving) have javascript 1.6
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
On the same page there is also an equivalent function if you don't have the function implemented natively into the engine.
For further references on array methods you can read
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array
精彩评论