JavaScript数组删除指定元素

^_^

function arrayRemoveItem(arr, delVal) {
    if (arr instanceof Array) {
        var index = arr.indexOf(delVal);
        if (index > -1) {
            arr.splice(index, 1);
        }
    }
}

Demo

// 在浏览器Console执行Demo
>function arrayRemoveItem(arr, delVal) {
>    if (arr instanceof Array) {
>        var index = arr.indexOf(delVal);
>        if (index > -1) {
>            arr.splice(index, 1);
>        }
>    }
>}
>var arr = ["a", "b", "c", "d", "e", "f", "g"];
>arr
<(7) ["a", "b", "c", "d", "e", "f", "g"]
>arrayRemoveItem(arr, 'd');
>arr
<(6) ["a", "b", "c", "e", "f", "g"]

:)

原文地址:https://www.cnblogs.com/gotodsp/p/9599151.html