javascript数组操作怎么删除特定的值
PHPz
PHPz 2017-04-10 12:47:58
0
3
789
var itemarrays=["足球","篮球","网球"];

有没有一个函数可以删除里面的值呢? 例如
itemarrys.del("篮球")这样子
目前我是用jquery的$.inArray("");
var index=$.inArray("篮球",itemarrays)
返回key然后再用.
itemarrys.splice(index,1);
删除
但是我觉得这样不够漂亮。请问有没有简单点的方法呢?
.del()是不是一定要自己写呢?

PHPz
PHPz

学习是最好的投资!

全部回覆(3)
数据分析师

javascript數組操作怎麼刪除特定的值-PHP中文網問答-javascript數組操作怎麼刪除特定的值-PHP中文網問答

圍觀一下哦,學習一下。

巴扎黑
Object.prototype.del=function(v){
    var i;
    for(i in this){
        if(this[i]===v)
            this.splice(i,1);
    }
};
迷茫

itemarrays.splice(itemarrays.indexOf('篮球'),1)

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!