下面是我为这个简单任务编写的javascript代码:
如果元素存在于数组中,则对其执行
如果元素不在数组中,则使用
if(_.contains(this.types,type_id)){ var index = this.types.indexOf(type_id);this.types.splice(index,1);} else{ this.types.push(type_id);}
有没有更有效的方法来做到这一点?
https://stackoverflow.com/questions/17153238
复制相似问题