Back

str.trimRight()

str.trimRight()

The trimRight() method removes whitespace from the right end of a string.

Syntax

str.trimRight()

Description

The trimRight() method returns the string stripped of whitespace from its right end. trimRight() does not affect the value of the string itself.

Examples

Using trimRight()

The following example displays the lowercase string ' foo':

var str = '   foo  ';

console.log(str.length); // 8

str = str.trimRight();
console.log(str.length); // 5
console.log(str);        // '   foo'

[Not part of any standard. Implemented in JavaScript 1.8.1.]


  Created by Mozilla Contributors, license: CC-BY-SA 2.5