Home > Web Front-end > JS Tutorial > A simple way to add whether Array contains a string using JS

A simple way to add whether Array contains a string using JS

高洛峰
Release: 2016-12-08 14:03:47
Original
1293 people have browsed it

The Array type of JS does not have a method to determine whether it contains a certain string. The following code implements this function. Students in need can take a look:

Array.prototype.contains = function(v){
  var b = false;
  for(var i=0;i<this.length;i++){
    if(this[i] == v){
      b = true;
      break;
    }
  }
  return b;
};
Copy after login


Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template