一、js删除数组中指定元素json
好比:数组
var arry = [ 'a','b','c' ,'d' ];函数
要删除 ‘c’spa
//获取到c的索引索引
var index = array.indexOf('c');io
//使用splice函数进行移除class
if (index > -1) {d3
array.splice(index, 1); 总结
}移动
二、js删除json里指定元素
好比:
var json = {
"a":{
"name":"支线物流",
"show":0,
"line_show":0,
"duration":500,
},
"b":{
"name":"移动货柜",
"show":0,
"line_show":0,
"duration":500,
},
"c":{
"name":"自动环卫",
"show":0,
"line_show":0,
"duration":1000,
},
"d":{
"name":"干线物流",
"show":0,
"line_show":0,
"duration":1000,
},
"e":{
"name":"robotaxi",
"show":0,
"line_show":0,
"duration":500,
}
}
要删除c这个元素
delete json["c"];
总结:要把纯数组于json数组分清楚