首页 > 技术文章 > js如何实现php的in_array()

jinshuo 2017-04-05 17:05 原文

var arr = [ 4, "Pete", 8, "John" ];
jQuery.inArray("John", arr);  //3
jQuery.inArray(4, arr);  //0
jQuery.inArray("David", arr);  //-1
jQuery.inArray("Pete", arr, 2);  //-1
如果作为判断条件,一定要注意.
找到返回数组下标,没有返回-1.

推荐阅读