js中的in_array

Array.prototype.S = String.fromCharCode(2);
Array.prototype.in_array = function (e) {
  var r = new RegExp(this.S + e + this.S);
  return (r.test(this.S + this.join(this.S) + this.S));
};

var ary = new Array(1,2,'aaa','bbbb',5);
alert(ary.in_array(3)); //false

alert(ary.in_array(2)); //true

原文地址:https://www.cnblogs.com/YTzZ/p/4563443.html