簡單字串處理 - daniel-qa/Vue GitHub Wiki
簡單字串處理
// 判斷是否去除前後 [ ]
const removeBracketsIfNeeded = (str) => {
// 判断首尾是否是方括号
if (str.startsWith('[') && str.endsWith(']')) {
return str.slice(1, -1); // 去掉首尾字符
}
return str; // 如果不是,直接返回原字符串
};