Home >Web Front-end >JS Tutorial >A simple way to add whether Array contains a string using JS
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; };