1、为Array原型添加indexOf方法(如果学过面向对象,相当于给Array类添加实例方法),方法体如下:
//添加数组IndexOf方法
if (!...len; from++){
if (from in this && this[from] === elt)
return from;
}
return -1;...};
}
2、使用jQuery的inArray方法,注:jQuery版本2.0以上不再支持IE8
var arr = [ 1, "2", false, "aaa" ];
jQuery.inArray...("aaa", arr);
jQuery.inArray(false, arr);
jQuery.inArray("2", arr);
jQuery.inArray(1, arr, 2);...不存在就为-1;