Javascript String mthToLastElement()

Description

Javascript String mthToLastElement()


String.prototype.mthToLastElement = function () {
 var mthArray = this.split(" ").reverse();
 var idx = mthArray.shift();
 if (idx > mthArray.length) {
  return undefined;
 } else {/*from   w w  w.jav a  2  s.  c o  m*/
  return mthArray[idx-1];
 }
}

console.log(line.mthToLastElement());



PreviousNext

Related