JavaScript 删除数组中指定元素
JavaScript 大约 348 字slice(index, number)
index
:表示从第几个元素开始。
number
:表示从此元素开始,向后删除几个元素。
代码
const arr = ['apple', 'banana', 'orange', 'other']
arr.map((item, index) => {
console.log(item, index, arr)
if (item === 'banana') {
arr.splice(index, 1);
}
})
参考
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
阅读 51 · 发布于 2023-01-17
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Java 并发编程之 AQS ReentrantLock 公平锁源码解析阅读 1076
-
Kubernetes 搭建之 Docker 安装阅读 693
-
软考-系统架构设计师:数据备份阅读 1725
-
Spring Boot 配置文件中的默认值阅读 379
-
start.spring.io 无法访问解决办法阅读 5013
-
Alpine Linux 安装 chattr阅读 552
-
Linux CentOS6 安装 Docker阅读 4144
-
Linux 之 -bash pecl command not found 的解决方法阅读 3769
-
Golang 关键字阅读 1874
-
Kubernetes Ingress 控制器 Nginx阅读 766