map 获取数组下标
时间: 2023-09-07 10:12:42 浏览: 322
使用map方法获取数组下标的代码是:
```javascript
var arr = [23,45,312,3213,53,23];
var index = arr.map(function(element, i) {
return i;
});
console.log(index);
```
输出结果为:[0, 1, 2, 3, 4, 5] 。
这段代码通过map方法遍历数组,并将每个元素的下标返回成一个新的数组。在这个例子中,输出的结果是一个包含每个元素下标的数组[0, 1, 2, 3, 4, 5]。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [js通过数组内容来获取数组下标](https://blog.csdn.net/weixin_44867717/article/details/125618372)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [详解ES6数组方法find()、findIndex()的总结](https://download.csdn.net/download/weixin_38683193/14801539)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文