Javascript Array elementsStartingWith(currentWord, ignoreCase)

Description

Javascript Array elementsStartingWith(currentWord, ignoreCase)


Array.prototype.elementsStartingWith = function (currentWord, ignoreCase) {
 var result = [];
 for (var i = 0; i<this.length; i++) {
  var localWord = this[i].substring(0, currentWord.length);
  if ( localWord ===  currentWord || (ignoreCase && currentWord.toLowerCase() === localWord.toLowerCase()) )
   result.push(this[i]);/*from   w  w  w . j a  va 2 s .c  om*/
 }
 return result;
}



PreviousNext

Related