var itemarrays=["足球","篮球","网球"];
有没有一个函数可以删除里面的值呢? 例如 itemarrys.del("篮球")这样子 目前我是用jquery的$.inArray(""); var index=$.inArray("篮球",itemarrays) 返回key然后再用. itemarrys.splice(index,1);删除 但是我觉得这样不够漂亮。请问有没有简单点的方法呢? .del()是不是一定要自己写呢?
学习是最好的投资!
How to delete specific values in javascript array operations-PHP Chinese website Q&A-How to delete specific values in javascript array operations-PHP Chinese website Q&A
Take a look around and learn.
Object.prototype.del=function(v){ var i; for(i in this){ if(this[i]===v) this.splice(i,1); } };
itemarrays.splice(itemarrays.indexOf('篮球'),1)
How to delete specific values in javascript array operations-PHP Chinese website Q&A-How to delete specific values in javascript array operations-PHP Chinese website Q&A
Take a look around and learn.
itemarrays.splice(itemarrays.indexOf('篮球'),1)