Skip to content

Instantly share code, notes, and snippets.

@simplelife7
Created December 30, 2013 16:19
Show Gist options
  • Save simplelife7/8184188 to your computer and use it in GitHub Desktop.
Save simplelife7/8184188 to your computer and use it in GitHub Desktop.
【JS】删除数组里的指定元素
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