js array contains an element of judgment

   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

Guess you like

Origin www.cnblogs.com/wwj007/p/12598685.html