开发者

javascript function for php in_array() like non numeric Index

开发者 https://www.devze.com 2023-04-13 03:16 出处:网络
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 fun

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

0

精彩评论

暂无评论...
验证码 换一张
取 消