如果没有,我想在字符串的开头和结尾添加空格。
如果开头有空格则在末尾添加,如果末尾有空格则在开头添加
var string='This is test';
=>
var string=' This is test ';
或
var string='This is test ';
=> 只会添加在开头
var string=' This is test ';
最佳答案
这很简单。检查以下内容:
let string ='This is test';
console.log(string); // No space
console.log(" " + string.trim() + " "); // space at start and end
关于javascript - 在字符串的开头和结尾添加空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50207827/