The trim()
method removes all leading and trailing white space:
The trim() method does not change the original string.
trim() |
Yes | 9.0 | Yes | Yes | Yes |
stringObject.trim();
None.
A string with no whitespace from both ends.
var stringValue = " hello world ";
var trimmedStringValue = stringValue.trim();
console.log(stringValue); //" hello world "
console.log(trimmedStringValue); //"hello world"
The original string remains intact.
The code above generates the following result.