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

posted @ 2020-03-30 15:04  wwj007  阅读(1038)  评论(0编辑  收藏  举报
……