JSFiddle - React, Tailwind, and code Playground
by Shang-De You
JavaScript
let article = 'aa統一超商1bbbccc統一超商2ccccc統一超商3ddddddd'
//let keyword1 = '統一超商股份有限公司'
let keyword1 = '統一超商'
// -- 先建立索引 --
let indexData = []
let keywordLength = keyword1.length
// let leftCropIndexArr = []
// let rightCropIndexArr = []
let leftCropMaxLength = keywordLength - 1
for (let n = leftCropMaxLength; n > 0; n--) {
// leftCropIndexArr.push([0, n]) // 左側截取索引
// rightCropIndexArr.push([n, keywordLength]) // 右側截取索引
let left = keyword1.substring(0, n)
let right = keyword1.substring(n, keywordLength)
indexData.push({
left,
right
})
}
console.log(indexData)
function replaceLeftRightText () {
}
// console.log(leftCropIndexArr)
// console.log(rightCropIndexArr)
// -- --
/* function () {
}
*/