String trim()
str.trim()
str
is a string
trim() method makes a copy of the given string, removes whitespace characters from the edges of the string, and returns the resulting string. original string str
is not modified.
Examples
1. remove whitespaces around edges
let name = ' apple ';
let output = name.trim();
console.log(output);
2. remove newline and tab spaces
let name = '\n apple \n\n \t ';
let output = name.trim();
console.log(output);