//JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。
let str = "a3b1cqwer2d4e5"
const n1 = "5"
const replaceIndex = 4
function getStartIndex(num, pos, str) {
let index = 0 // 最终下标
let times = 0 // 循环次数条件
let fontIndex = 0 // 记住每次切割之前的下标计算总下标
while (times <= pos) {
if (pos > 0 && times !== pos)
fontIndex += (str.indexOf(num) + 1)
if (times === pos)
index = str.indexOf(num) + fontIndex
str = str.substring(str.indexOf(num) + 1)
times++
}
return index
}
const index = getStartIndex(n1,replaceIndex,str)
console.log(index)