远昼

文章 评论 浏览 32

远昼 2022-05-04 13:54:23

Array.prototype.myIndexOf = function (value, fromIndex) {
const len = this.length
let index = -1
fromIndex = fromIndex === undefined ? 0 : fromIndex
if (fromIndex < 0) {
fromIndex = len + fromIndex;
fromIndex = fromIndex < 0 ? 0 : fromIndex;
}
for (let i = fromIndex; i < len; i++) {
if (this[i] === value) {
index = i;
break;
}
}
return index
}

第 151 题:用最简洁代码实现 indexOf 方法?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文