Add prototype array using the chain determines whether the field is present in the array

Ado, directly on the code

Array.prototype.isRepeat = function(str){
  var i = this.length;
  while(i){
    i--;
    if(this[i]==str){
      return true;
    }
  }
  return false;
}

###############用法
let arr = [1,2,3,4,5,6,7];
var str = 4;
console.log(arr.isRepeat (str))  //true

Guess you like

Origin blog.csdn.net/qq_42363090/article/details/93486846