码迷,mamicode.com
首页 > 编程语言 > 详细

js 数组删除指定元素

时间:2015-09-26 10:28:43      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

 1 Array.prototype.remove = function(obj) {
 2                         for (var i = 0; i < this.length; i++) {
 3                             var temp = this[i];
 4                             if (!isNaN(obj)) {//isNaN() 函数用于检查其参数是否是非数字值。
 5                                 temp = i;
 6                             }
 7                             if (temp == obj) {//判断当前值,和我想要删除的值是否相等
 8                                 for (var j = i; j < this.length; j++) {
 9                                     this[j] = this[j + 1];//若是相等,从i向后顺次向前移动一位
10                                 }
11                                 this.length = this.length - 1;
12                             }
13                         }
14                     }

 注:从其他地方找到的,并非原创。

js 数组删除指定元素

标签:

原文地址:http://www.cnblogs.com/LIU-ZHENYU/p/4840031.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!