您当前的位置: 首页 >  ar

暂无认证

  • 0浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Array.prototype.myfindIndex

发布时间:2022-03-31 17:07:48 ,浏览量:0

目录
  • 1、概念
  • 2、MDN链接地址
  • 3、示例代码
1、概念

findIndex()方法返回数组中满足提供的测试函数的第一个元素的索引(下标)。若没有找到对应元素则返回-1。

2、MDN链接地址

MDN - findIndex

3、示例代码
let arrayData = [4, 6, 8, 12]; Array.prototype.myfindIndex = function(callback, context) { // 获取第二个参数, // 即this指向。 // 如果有直接使用, // 否则,指向window context = context || window; // 获取this的长度。 let len = this.length; // 初始化while的值。 let i = 0; while (i < len) { // 调用函数 if (callback.call(context, this[i], i, this)) return i; i++; }; return -1; }; let fun = function(item) { return item + this.svalue > 10; }; console.log(arrayData.myfindIndex(fun, { svalue: 5 })); // 1 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.8679s