Truncate String by length - Node.js String

Node.js examples for String:Length

Description

Truncate String by length

Demo Code

String.prototype.truncate = function(length) {
  return this.substr(0, length - 1) + (this.length > length? '...' : '');
}

Related Tutorials