Javascript trim()
method creates a copy of the string and removes all leading and trailing white space, and returns the result.
str.trim()
let stringValue = " hello world "; let trimmedStringValue = stringValue.trim(); console.log(">"+stringValue+"<"); console.log(">"+trimmedStringValue+"<");
The trim()
returns a copy of a string.
The original string remains intact with leading and trailing white space.