function
removeByValue(arr, val) {
for
(
var
i=0; i<arr.length; i++) {
if
(arr[i] == val) {
arr.splice(i, 1);
break
;
}
}
}
var
somearray = [
"mon"
,
"tue"
,
"wed"
,
"thur"
]
removeByValue(somearray,
"tue"
);
Array.prototype.removeByValue =
function
(val) {
for
(
var
i=0; i<
this
.length; i++) {
if
(
this
[i] == val) {
this
.splice(i, 1);
break
;
}
}
}
var
somearray = [
"mon"
,
"tue"
,
"wed"
,
"thur"
]
somearray.removeByValue(
"tue"
);
<html>
<body>
<button type="button" οnclick="test()">Click Me!</button>
<script type="text/javascript">
var codes = new Array();
Array.prototype.removeByValue = function(val) {
for(var i=0; i<this.length; i++) {
if(this[i] == val) {
this.splice(i, 1);
break;
}
}
}
function test(){
codes.push("aa");
codes.push("cc");
codes.push("bb");
codes.removeByValue("aa");
for(var i =0 ; i < codes.length ; i++){
alert(codes[i]);
}
}
</script>
</body>
</html>