Javascript通过元素名删除数组中该元素

admin 2023年11月8日23:51:36脚本语言评论2,190 次浏览阅读模式
Array.prototype.remove = function (val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
}
 
var arr = ['apple', 'banana', 'orange', 'pear']
 
arr.remove('banana')
 
console.log(arr)    // ['apple', 'orange', 'pear']

js

相关文章
weinxin
我的微信
微信扫一扫
admin
  • 本文由 发表于 2023年11月8日23:51:36
  • 转载请务必保留本文链接:https://anyun.org/a/jishuguanzhu/bianchengchalou/jiaobenyuyan/2023/1108/14134.html