I'm having an issue with trimming white spaces from a string in JavaScript. Here's my code:
<script>
let str = " Hello, I need to trim this string. ";
let trimmedStr = str.trim();
console.log(trimmedStr);
</script>
The problem is that the trim() method only removes leading and trailing white spaces, but I want to remove all white spaces. Any suggestions on how to achieve this?
Comments (1)
How to trim() white spaces from a string?
<script>
let str = " Hello, I need …