String.prototype.trim ( )
Return result of StringTrim
abstract operation passing this value as thisArg
, and TrimBoth
as the type
.
String.prototype.trimRight ( )
Return result of StringTrim
abstract operation passing this value as thisArg
, and TrimRight
as the type
.
String.prototype.trimLeft ( )
Return result of StringTrim
abstract operation passing this value as thisArg
, and TrimLeft
as the type
.
NOTE: The trim, trimLeft, and trimRight functions are intentionally generic; they do not require that their this value be a String object. Therefore, they can be transferred to other kinds of objects for use as a method.
StringTrim(thisArg, type) abstract operation
This function interprets a string value as a sequence of UTF-16 encoded code points, as described in <...>.
The following steps are taken:
- Let O be
RequireObjectCoercible
(thisArg). - Let S be ToString(O).
ReturnIfAbrupt
(S).- Let T be a String value that is a copy of S with:
- if type is
TrimBoth
, then with both leading and trailing white space removed - else if type is
TrimRight
, then with trailing white space removed - else if type is
TrimgLeft
, then both leading white space removed - NOTE: The definition of white space is the union of WhiteSpace and LineTerminator. When determining whether a Unicode code point is in Unicode general category "Zs", code unit sequences are interpreted as UTF-16 encoded code point sequences as specified in <...>.
- Return T.