js 按照指定字符串切割成数组并加入该字符串
this.returnText("企业查询","查询")
//返回查询字符串
returnText(record,text){
let value=record.split(text)||[]
let valueNew=JSON.parse(JSON.stringify(value))
value.map((item,index)=>{
if(index!==value.length-1){
valueNew.splice(index+1,0,text)
}
})
return valueNew
}
console.log(this.returnText("企业查询","查询"))
//打印结果为:["企业","查询"]
console.log(this.returnText("企业查询测试","查询"))
//打印结果为:["企业","查询","测试"]