Created
December 30, 2013 16:19
-
-
Save simplelife7/8184188 to your computer and use it in GitHub Desktop.
【JS】删除数组里的指定元素
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.deleteElementByValue = function(varElement) | |
{ | |
var numDeleteIndex = -1; | |
for (var i=0; i<this.length; i++) | |
{ | |
// 严格比较,即类型与数值必须同时相等。 | |
if (this[i] === varElement) | |
{ | |
this.splice(i, 1); | |
numDeleteIndex = i; | |
break; | |
} | |
} | |
return this; | |
} | |
var arr = new Array("31","52","73","24"); | |
alert(arr.deleteElementByValue("73")); // [31,52,24] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment