indexof用于数组去重
时间: 2023-10-19 11:28:11 浏览: 107
indexOf方法可以用于数组去重。它可以返回某个指定的元素在数组中首次出现的位置。使用indexOf和新建一个空的结果数组,可以对原数组进行遍历判断,如果元素不在结果数组中,则将其push进结果数组中,最后得到去重后的数组。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [js数组去重](https://blog.csdn.net/cddcj/article/details/126102557)[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_2"}}] [.reference_item style="max-width: 50%"]
- *2* [includes()方法和indexOf()方法数组去重](https://blog.csdn.net/lijiangzhao/article/details/108500065)[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_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文