这个错误提示表明您正在尝试在一个字符串数组上使用 trim
方法,但数组类型没有这个方法。trim
方法是字符串(string
)类型的方法。
您可能需要检查您的代码,确认您正在操作的对象是单个字符串而不是字符串数组。如果您想要对数组中的每个字符串进行 trim
操作,可以使用数组的遍历方法来实现。
// 1. 切割为数组
const branchFilter: string = ' 全部分路 | 对抗路 | 中路 | 发育路 | 游走 | 打野 '
const tabFilter: string = ' 所有段位 - 巅峰赛1350+ - 顶端排位 - 赛事 '
// 2. 获取日期
const dateStr:string = '2024-04-27'
//使用split方法将字符串分割为数组,打印出来
console.log('branchFilter -----> ', branchFilter.trim().split("|"))//true
console.log('tabFilter -----> ', tabFilter.split("-").trim()) //false
String用法可以看