Javascript String truncate(length, truncation)
String.prototype.truncate = function(length, truncation) { length = length || 30;//w w w.ja v a 2 s . c om truncation = truncation === undefined ? '...' : truncation; return this.length > length ? this.slice(0, length - truncation.length) + truncation : String(this); };