当前位置:网站首页>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
边栏推荐
- Why do job hopping take more than promotion?
- el-table表格——sortable排序 & 出现小数、%时排序错乱
- 【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
- js中,字符串和数组互转(一)——字符串转为数组的方法
- OSPF多区域配置
- Ravendb starts -- document metadata
- 【OpenCV 例程200篇】220.对图像进行马赛克处理
- Is it profitable to host an Olympic Games?
- document.write()的用法-写入文本——修改样式、位置控制
- C language games - minesweeping
猜你喜欢
OneNote in-depth evaluation: using resources, plug-ins, templates
面试官:Redis中有序集合的内部实现方式是什么?
Variable star --- article module (1)
Deployment of external server area and dual machine hot standby of firewall Foundation
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
None of the strongest kings in the monitoring industry!
New database, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, Feishu multidimensional table, heipayun, Zhixin information, YuQue
PHP online examination system version 4.0 source code computer + mobile terminal
Is this the feeling of being spoiled by bytes?
2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
随机推荐
Yyds dry inventory run kubeedge official example_ Counter demo counter
No Yum source to install SPuG monitoring
基于深度学习的参考帧生成
【Redis设计与实现】第一部分 :Redis数据结构和对象 总结
SAP Fiori应用索引大全工具和 SAP Fiori Tools 的使用介绍
Aiko ai Frontier promotion (7.6)
OneNote 深度评测:使用资源、插件、模版
什么是RDB和AOF
js通过数组内容来获取数组下标
PHP saves session data to MySQL database
Spiral square PTA
R語言可視化兩個以上的分類(類別)變量之間的關系、使用vcd包中的Mosaic函數創建馬賽克圖( Mosaic plots)、分別可視化兩個、三個、四個分類變量的關系的馬賽克圖
None of the strongest kings in the monitoring industry!
What key progress has been made in deep learning in 2021?
Comprehensive evaluation and recommendation of the most comprehensive knowledge base management tools in the whole network: flowus, baklib, jiandaoyun, ones wiki, pingcode, seed, mebox, Yifang cloud,
967- letter combination of telephone number
Web开发小妙招:巧用ThreadLocal规避层层传值
@PathVariable
Statistical inference: maximum likelihood estimation, Bayesian estimation and variance deviation decomposition
ICML 2022 | flowformer: task generic linear complexity transformer