当前位置:网站首页>JS get array subscript through array content
JS get array subscript through array content
2022-07-06 21:10:00 【viceen】
js Get the array subscript through the array content
demand : By knowing something in the array , Then delete the array through this content , Is to find the subscript of the array by looping , Then take it to delete .
Method 1:js How to write it
var arr = [1, 1, 2, 12, 3, 23, 5, 6, 45]; // Array
var k = 12;// To find the contents of the array
var c = [];// The subscript of the array obtained by content
// Get subscript
for (var i = 0; i < arr.length; i++) {
if (k == arr[i]) {
c.push(i)
}
}
console.log(c) // [3]
Method 2:ES6 Of map grammar ,
Although code introduction , But you can only find the first , Some places just need the first one , If there is a repetition , You can use the first method .
var arr = [23,45,312,3213,53,23]
var index = arr.map(item => item).indexOf(23)
console.log(index) // 0
边栏推荐
- Seven original sins of embedded development
- [MySQL] basic use of cursor
- 【mysql】触发器
- PHP online examination system version 4.0 source code computer + mobile terminal
- How do I remove duplicates from the list- How to remove duplicates from a list?
- Is it safe to open an account in flush? Which securities company is good at opening an account? Low handling charges
- None of the strongest kings in the monitoring industry!
- 数据湖(八):Iceberg数据存储格式
- Nodejs tutorial let's create your first expressjs application with typescript
- Web开发小妙招:巧用ThreadLocal规避层层传值
猜你喜欢
3D人脸重建:从基础知识到识别/重建方法!
The most comprehensive new database in the whole network, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, flying Book Multidimensional table, heipayun, Zhix
爱可可AI前沿推介(7.6)
Study notes of grain Mall - phase I: Project Introduction
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
968 edit distance
每个程序员必须掌握的常用英语词汇(建议收藏)
【mysql】游标的基本使用
Common English vocabulary that every programmer must master (recommended Collection)
面试官:Redis中有序集合的内部实现方式是什么?
随机推荐
防火墙基础之外网服务器区部署和双机热备
Distributed ID
审稿人dis整个研究方向已经不仅仅是在审我的稿子了怎么办?
Nodejs教程之Expressjs一篇文章快速入门
Is this the feeling of being spoiled by bytes?
No Yum source to install SPuG monitoring
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
每个程序员必须掌握的常用英语词汇(建议收藏)
What is the difference between procedural SQL and C language in defining variables
R language visualizes the relationship between more than two classification (category) variables, uses mosaic function in VCD package to create mosaic plots, and visualizes the relationship between tw
Opencv learning example code 3.2.3 image binarization
如何实现常见框架
el-table表格——sortable排序 & 出现小数、%时排序错乱
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
【OpenCV 例程200篇】220.对图像进行马赛克处理
Nodejs tutorial let's create your first expressjs application with typescript
C # use Oracle stored procedure to obtain result set instance
document.write()的用法-写入文本——修改样式、位置控制
MLP (multilayer perceptron neural network) is a multilayer fully connected neural network model.
User defined current limiting annotation