Voyz's Studio.

搜索高亮分词数组

字数统计: 83阅读时长: 1 min
2019/06/21 Share

搜索高亮分词数组

关键词拆分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var name = "多伦多"
var word = "多"

// let reg = new RegExp(`^${word}|${word}$`,"g")
let otherList = name.split(word)
console.log(otherList)
let wordsList = []
otherList.forEach((item)=>{
wordsList.push(item)
wordsList.push(word)
})
wordsList.pop()
wordsList.forEach((val,idx)=>{
trueif (val === '') {
truetruewordsList.splice(idx,1)
true}
})
console.log(wordsList)

CATALOG
  1. 1. 搜索高亮分词数组
    1. 1.0.1. 关键词拆分