js数组中删除具体元素

1.使用splice

//获取这个元素在数组中的位置
let index = this.array.indexOf(val);
//大于-1说明存在,splice删去
if (index > -1) {
	this.array.splice(index, 1);
}

2.使用delete

let array = ['a','b','c','d']; 
delete array [0]; 
//结果 array :[undefined × 1, "b", "c", "d"] 
//数组长度不变,有一项为undefined
发布了23 篇原创文章 · 获赞 0 · 访问量 2669

猜你喜欢

转载自blog.csdn.net/xy405580364/article/details/102796139
今日推荐