function fn(str, target) {
let res = new RegExp(target, 'g').exec(str)
return res ? res.index : -1
}
console.log('打印', fn('hello word', 'l'))
// 打印 2
用最简洁代码实现indexOf方法
猜你喜欢
转载自www.cnblogs.com/liea/p/12508707.html
今日推荐
周排行