Javascript String subString()
method
String.prototype.subString = function(){ var arr = []; for(var i = 0; i < this.length; i++){ for(var j = i + 1; j < this.length + 1; j++){ arr.push(this.slice(i, j));// w w w.j a v a2 s .c o m } } return arr; } console.log("dog".subString());
String.prototype.subString = function() { /* ww w .j av a 2 s.co m*/ var subset = []; for (var m = 0; m < this.length; m++) { for (var n = m+1; n<this.length+1; n++) { subset.push(this.slice(m,n)); } } return subset; }; console.log("dog".subString());
String.prototype.substring = function(){ var returnArray = []; for (var i = 0; i < this.length; i++) { for(var j = i; j< this.length; j++){ returnArray.push(this.slice(i,j+1));//from w w w . j av a2 s .c o m } }; return returnArray; } var str = "cat" console.log(str.substring())
String.prototype.subString = function(){ let subs = [];/*from w ww. ja v a 2s. c o m*/ for (let i = 0; i <= this.length - 1; i++) { for (let j = i + 1; j <= this.length; j++) { subs.push(this.slice(i, j)); } } return subs; }; console.log("cat".subString());
String.prototype.substring = function() { var result = []; for (var i = 0; i < this.length; i++) { for (var j = i + 1; j < this.length + 1; j++) { result.push(this.slice(i,j))//from ww w. j a v a2 s.c o m } } return result; } var word = "catx"; console.log(word.substring());