Table Maker3schools TranslateImage CompressorFavicon Icon GeneratorCrop & Resize Image
Apu
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
1 Answer
Write Your Answer
loading
back
View All