trim() method by using that we can remove the whitespaces from the both ends of a string.
Here is an example that trims the following string:
const name = " olive "; console.log(name.trim()); // "olive"
Similarly, we can also use the
join() methods to trim the string.
const name = " olive "; const trimmedString = name.split(" ").join("")); console.log(trimmedString); // "olive"