Javascript 从json数组中删除特定元素

Javascript 从json数组中删除特定元素,javascript,jquery,arrays,json,Javascript,Jquery,Arrays,Json,我这样声明了一个JSON var json{ section1: [], section2: [], section3: [] } 我想以这种方式或类似方式删除特定项目 json[section][index].remove(); 我试过用这种方法 delete json[section][index]; 但是当我这样做时,数组元素不会重新排列slice()是您的朋友 数组没有remove功能。改用拼接: var data={section1:[1,2,3,4]}; 常量remov

我这样声明了一个JSON

var json{
section1: [],
section2: [],
section3: []
} 
我想以这种方式或类似方式删除特定项目

json[section][index].remove();
我试过用这种方法

 delete json[section][index];
但是当我这样做时,数组元素不会重新排列
slice()
是您的朋友


数组没有
remove
功能。改用
拼接

var data={section1:[1,2,3,4]};
常量remove=(arr,key,index)=>arr[key]。拼接(index,1)
删除(数据,“第1节”,第2节)

console.log(数据)
您可以使用
splice()
从数组中删除项。-->如果您只想根据名为
index
的数字删除特定属性,则可以执行
delete json[“section”+index]
Slice将返回一个浅拷贝(在这种情况下是数组的单个元素)。您不会更改原始数组,也不会返回任何类型的已更改数组。你把切片和拼接混在一起了吗?不可否认,他们所操纵的阵列是否不仅仅是一个简单的阵列还不清楚@阿索隆,你的答案还是比较好的。为了完整起见,我想我会把这个放在这里。我使用切片来删除元素。我这样做:json[place].splice(位置,1);谢谢
json[section] = json[section].slice(index,index+1);