How to remove whitespace in text
trim() only removes whitespaces from the start and end of a string:
https://www.w3schools.com/Jsref/jsref_trim_string.asp
have a look here to remove whitespaces between strings:
Replace all whitespace characters
the relevant part is to use it like:
str = str.replace(/\s/g, "X");
According to the docs, the trim() method removes trailing and leading whitespaces, not those in the middle.
https://www.w3schools.com/Jsref/jsref_trim_string.asp
If you want to remove all whitespaces use the replace
function:
"name abc".replace(/\s/g, "");