How to solve this problem??
The idea is that we use the regular match to the so-called space, and then replace the null character, we need to use the STR's replace API
The code is as follows:
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Document</title>6 </Head>7 <Body>8 <Script>9 //remove spaces at the beginning and end of a stringTen functiondelate (str) { One //match the space to the beginning, and then replace it with a blank, returning a new string str1 A Let str1=Str.replace (/\s+$/,"'); - //back to str2 - the Let str2=Str1.replace (/^\s+/,"') - returnstr2; - } - Console.log (Delate ('text')); + Console.log ('text'); - </Script> + </Body> A </HTML>
Note: Replace is replaced by the previous one, and then the null character is replaced with \s, and then with what starts with ^.
Native JS-remove null characters at the beginning and end of a string