Javascript String truncate(options)

Description

Javascript String truncate(options)


String.prototype.truncate = function (options) {
  var length = (options && options.length) || 50;
  var ending = (options && options.ending) || "...";
  var truncated = this.slice(0, length);

  if (truncated.length < this.length)
    truncated += ending;/* w  ww. j  a  va  2s.  c o m*/

  return truncated;
};



PreviousNext

Related