Javascript String Prototype Shorten

Description

Javascript String Prototype Shorten


String.prototype.shorten = function(count) {
  if (this.length > count+2)
    return this.slice(0, count-1).replace(/[\s]+$/g, "")+String.fromCharCode(8230);  
  else//from  w  w w  . j  a v a  2s  . c  o  m
    return this;
}


let myString = "The quick brown fox.";

console.log( myString.shorten(11) );



PreviousNext

Related