六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 19|回复: 0

javascript 数组删除某个元素

[复制链接]

升级  25.67%

81

主题

81

主题

81

主题

举人

Rank: 3Rank: 3

积分
277
 楼主| 发表于 2013-1-29 08:54:11 | 显示全部楼层 |阅读模式
/** 删除数组指定下标的元素.*/Array.prototype.remove = function ( dx ) {if (isNaN(dx) || dx > this.length) {return false;}for (var i = 0, n = 0; i < this.length; i++) {if (this[i] != this[dx]) {this[n++] = this[i]}}this.length -= 1}/* * 在数组中获取指定值的元素索引 */Array.prototype.getArrayIndex = function ( value ) {var index = -1;for (var i = 0; i < this.length; i++) {if (this[i] == value) {index = i;break;}}return index;}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表