当前位置:网站首页>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
边栏推荐
- Ravendb starts -- document metadata
- R語言可視化兩個以上的分類(類別)變量之間的關系、使用vcd包中的Mosaic函數創建馬賽克圖( Mosaic plots)、分別可視化兩個、三個、四個分類變量的關系的馬賽克圖
- Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
- 爱可可AI前沿推介(7.6)
- Spiral square PTA
- [sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics
- JS操作dom元素(一)——获取DOM节点的六种方式
- 【微信小程序】運行機制和更新機制
- 审稿人dis整个研究方向已经不仅仅是在审我的稿子了怎么办?
- [wechat applet] operation mechanism and update mechanism
猜你喜欢

Swagger UI教程 API 文档神器

基于深度学习的参考帧生成

【OpenCV 例程200篇】220.对图像进行马赛克处理
![[wechat applet] operation mechanism and update mechanism](/img/cf/58a62a7134ff5e9f8d2f91aa24c7ac.png)
[wechat applet] operation mechanism and update mechanism

Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices

Intel 48 core new Xeon run point exposure: unexpected results against AMD zen3 in 3D cache

What key progress has been made in deep learning in 2021?

Study notes of grain Mall - phase I: Project Introduction

20220211 failure - maximum amount of data supported by mongodb

硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
随机推荐
Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices
Leetcode hot topic Hot 100 day 32: "minimum coverage substring"
Thinking about agile development
C language operators
基于STM32单片机设计的红外测温仪(带人脸检测)
OSPF多区域配置
Common English vocabulary that every programmer must master (recommended Collection)
PHP saves session data to MySQL database
[MySQL] basic use of cursor
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
KDD 2022 | 通过知识增强的提示学习实现统一的对话式推荐
Study notes of grain Mall - phase I: Project Introduction
Select data Column subset in table R [duplicate] - select subset of columns in data table R [duplicate]
Why do job hopping take more than promotion?
OSPF multi zone configuration
3D人脸重建:从基础知识到识别/重建方法!
Forward maximum matching method
Word bag model and TF-IDF
Is it safe to open an account in flush? Which securities company is good at opening an account? Low handling charges
C # use Oracle stored procedure to obtain result set instance