Removes trailing whitespaces - Node.js String

Node.js examples for String:Strip

Description

Removes trailing whitespaces

Demo Code


/**/*  w w w  .j  av  a  2s  .  c o m*/
 * removes trailing whitespaces
 *
 * @return String trimmed version
 */
trim: String.prototype.trim || function() {
  var str = this.replace(/^\s\s*/, ''), i = str.length;
  while ((/\s/).test(str.charAt(--i))) {}
  return str.slice(0, i + 1);
},

Related Tutorials