網站首頁 編程語言 正文
1、概念
findIndex()
方法返回數組中滿足提供的測試函數的第一個元素的索引(下標)。若沒有找到對應元素則返回-1。
2、MDN鏈接地址
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
原文鏈接:https://blog.csdn.net/weixin_51157081/article/details/115794916
相關推薦
- 2022-09-14 apache虛擬主機配置的三種方式(小結)_Linux
- 2022-08-13 Kafka復習計劃 - Kafka基礎知識以及集群參方案和參數
- 2022-10-16 python?os模塊使用方法介紹_python
- 2022-09-03 python?解決數據庫寫入時float自動變為整數的問題_python
- 2022-07-09 Nginx利用Logrotate實現日志分割的詳細過程_nginx
- 2022-06-01 Python中plt.plot()、plt.scatter()和plt.legend函數的用法示例_
- 2024-01-11 IDEA切換全屏模式
- 2022-05-18 C++中string類的常用方法實例總結_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支