用最简洁代码实现indexOf方法
function fn(str, target) {
let res = new RegExp(target, 'g').exec(str)
return res ? res.index : -1
}
console.log('打印', fn('hello word', 'l'))
// 打印 2
function fn(str, target) {
let res = new RegExp(target, 'g').exec(str)
return res ? res.index : -1
}
console.log('打印', fn('hello word', 'l'))
// 打印 2