String.prototype.trim() | javascript trim not working
Thetrim()methodofString[1]valuesremoveswhitespacefrombothendsofthisstringandreturnsanewstring,withoutmodifyingtheoriginalstring.Toreturnanewstringwithwhitespacetrimmedfromjustoneend,usetrimStart()[2]ortrimEnd()[3].Parameters[4]Returnvalue[5]Anewstringrepresentingstrstrippedofwhitespacefrombothitsbeginningandend.Whitespaceisdefinedaswhitespace[6]characterspluslineterminators[7].Ifneitherthebeginningorendofstrhasanywhitespace,anewstringisstillreturned(essentiallyacopyofstr).Usingtrim()[8]Thefo...
The trim() method of String[1] values removes whitespace from both ends of this string and returns a new string, without modifying the original string.
To return a new string with whitespace trimmed from just one end, use trimStart()[2] or trimEnd()[3].
Parameters[4]Return value[5]A new string representing str stripped of whitespace from both its beginning and end. Whitespace is defined as white space[6] characters plus line terminators[7].
If neither the beginning or end of str has any whitespace, a new string is still returned (essentially a copy of str).
Using trim()[8]The following example trims whitespace from both ends of str.
const str = " foo "; console.log(str.trim());BCD tables only load in the browser
with JavaScript enabled. Enable JavaScript to view data.References String (developer.mozilla.org) trimStart() (developer.mozilla.org) trimEnd() (developer.mozilla.org) Parameters (developer.mozilla.org) Return value (developer.mozill...