当前位置:网站首页>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
边栏推荐
- OSPF multi zone configuration
- js 根据汉字首字母排序(省份排序) 或 根据英文首字母排序——za排序 & az排序
- Distributed ID
- 正则表达式收集
- Kubernetes learning summary (20) -- what is the relationship between kubernetes and microservices and containers?
- el-table表格——获取单击的是第几行和第几列 & 表格排序之el-table与sort-change、el-table-column与sort-method & 清除排序-clearSort
- LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
- 面试官:Redis中有序集合的内部实现方式是什么?
- 代理和反向代理
- Infrared thermometer based on STM32 single chip microcomputer (with face detection)
猜你喜欢

Laravel笔记-自定义登录中新增登录5次失败锁账户功能(提高系统安全性)

2022 fields Award Announced! The first Korean Xu Long'er was on the list, and four post-80s women won the prize. Ukrainian female mathematicians became the only two women to win the prize in history

嵌入式开发的7大原罪

2017 8th Blue Bridge Cup group a provincial tournament

The biggest pain point of traffic management - the resource utilization rate cannot go up
![[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics](/img/2d/9a7e88fb774984d061538e3ad4a96b.png)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics

拼多多败诉,砍价始终差0.9%一案宣判;微信内测同一手机号可注册两个账号功能;2022年度菲尔兹奖公布|极客头条

Redis insert data garbled solution
![[MySQL] basic use of cursor](/img/cc/39b1e17b48d0de641d3cbffbf2335a.png)
[MySQL] basic use of cursor

2022菲尔兹奖揭晓!首位韩裔许埈珥上榜,四位80后得奖,乌克兰女数学家成史上唯二获奖女性
随机推荐
Web开发小妙招:巧用ThreadLocal规避层层传值
Seven original sins of embedded development
OAI 5g nr+usrp b210 installation and construction
js中,字符串和数组互转(二)——数组转为字符串的方法
3D人脸重建:从基础知识到识别/重建方法!
Three schemes of SVM to realize multi classification
@PathVariable
Performance test process and plan
No Yum source to install SPuG monitoring
华为设备命令
Forward maximum matching method
性能测试过程和计划
Spark SQL chasing Wife Series (initial understanding)
What is the difference between procedural SQL and C language in defining variables
Interviewer: what is the internal implementation of ordered collection in redis?
Pycharm remote execution
Thinking about agile development
如何实现常见框架
全网最全的知识库管理工具综合评测和推荐:FlowUs、Baklib、简道云、ONES Wiki 、PingCode、Seed、MeBox、亿方云、智米云、搜阅云、天翎
OAI 5G NR+USRP B210安装搭建