js判断数组是否包含某个元素

   dealArray(arr, obj) {
      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);
      };
      return arr.in_array(obj);
    },
   console.log(this.dealArray([1,1,12,34,3],34));//输出结果:true
   console.log(this.dealArray([1,1,12,34,3],4));//输出结果:false

猜你喜欢

转载自www.cnblogs.com/wwj007/p/12598685.html