 
Apu
January 19, 2024 › 
                         
                         
#HowTo
 › 
                            #Javascript
❌
How to trim() white spaces from a string?
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?
 save
 listen
 
    AI Answer
How to trim() white spaces from a string?
1
I'm having an issue with trimming white spaces from a string in JavaScript. Here'…
asked 
Apu
1 answers
2915
I'm having an issue with trimming white spaces from a string in JavaScript. Here'…
Answer Link
answered 
Apu
