js怎么删数组固定的值

 <script type="text/javascript">
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 array = [1, 2, 3, 4, 5];
array.remove(3);

</script>
posted @ 2017-05-18 21:34  春风得意之时  阅读(239)  评论(0编辑  收藏  举报