当前位置:网站首页>JS array delete the specified element

JS array delete the specified element

2022-07-07 11:08:00 Have a good time I

js There are many ways to delete a specified element , Here is the simplest
Add to array remove Method :

Array.prototype.remove = function(val) {
    
    var index = this.indexOf(val);
    if (index > -1) {
    
        this.splice(index, 1);
    }
}

The call mode is :

var element = "xx"
arr.remove(element)

Come back and summarize other methods when you have time

原网站

版权声明
本文为[Have a good time I]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130619539946.html