//获取元素下标 Array.prototype.indexOf = function(val){ for(var i = 0; i < this.length; i++){ if(this[i] == val){ return i; } } return -1; } //根据下标删除元素 Array.prototype.remove = function(val){ var index = this.indexOf(val); if(index > -1){ this.splice(index, 1); } } //测试 var roleNameArr = ['aa', 'bb', 'cc'] roleNameArr.remove('bb');
标签:function,index,删除,val,元素,js,数组,var,prototype From: https://www.cnblogs.com/spll/p/17598706.html