Variabel Inhalt nach String durchsuchen

Snippet erweitert String um die Methoden indexOf and contains.
Somit lässt sich der Inhalt einer Variable bequem einem String / Substring durchsuchen:
var langerstring = "a quick brown fox jumps over lazy dog";
var suchwort= "jumps";
if ((langerstring.contains(suchwort)){
alert("gefunden");
}

Like it? Share it!
if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(obj, start) { for (var i = (start || 0), j = this.length; i < j; i++) { if (this[i] === obj) { return i; } } return -1; } } if (!String.prototype.contains) { String.prototype.contains = function (arg) { return !!~this.indexOf(arg); }; }

>_ Author

>_ last updated 4 yearss ago

>_ Language: Java Script

String