
es6语法如何利用indexOf()和Array.splice()替换数组中指定元素,下面web建站小编给大家详细介绍一下!
利用indexOf()替换数组中指定元素
const arr = ['a', 'b', 'c'];
const index = arr.indexOf('a'); // ?️  0
if (index !== -1) {
  arr[index] = 's';
}
console.log(arr);
//(3) ['s', 'b', 'c']
利用Array.splice()替换数组中指定元素
const arr = ['a', 'b', 'c'];
const index = arr.indexOf('b'); // ?️  1
arr.splice(index, 1, 'h');
console.log(arr);
//['a', 'h', 'c']
标签: es6语法, indexOf, splice, 数组替换
上面是“es6语法如何替换数组中指定元素”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_2785.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

 {global.cfg_templets_skin}不解析地址怎么办
 {global.cfg_templets_skin}不解析地址怎么办 DeepSite V2:无需安装,只需通过简单的文字提示,即可快速生成网页
 DeepSite V2:无需安装,只需通过简单的文字提示,即可快速生成网页 3D粒子波浪动画效果three.js
 3D粒子波浪动画效果three.js js百分比动态球效果
 js百分比动态球效果