日期:2014-05-16  浏览次数:20308 次

javascript 数组删除某个元素
/*
* 删除数组指定下标的元素.
*/

	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;
}