Loading

用最简洁代码实现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
posted @ 2020-03-17 09:38  fsdffsdf  阅读(645)  评论(0编辑  收藏  举报