Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从json数组中删除记录_Javascript - Fatal编程技术网

Javascript 从json数组中删除记录

Javascript 从json数组中删除记录,javascript,Javascript,我有一个json数组,格式如下: Object {field: "l0", headerText: "0-22", width: 120} Object {field: "l1", headerText: "23-43", width: 120} Object {field: "l2", headerText: "44-55", width: 120} 我想根据headerText值删除一条记录 i、 e.我的值为0-22,在此基础上,我必须删除此记录。有可能吗?假设对象被包装在一个数组中,如

我有一个json数组,格式如下:

Object {field: "l0", headerText: "0-22", width: 120}
Object {field: "l1", headerText: "23-43", width: 120}
Object {field: "l2", headerText: "44-55", width: 120}
我想根据headerText值删除一条记录


i、 e.我的值为0-22,在此基础上,我必须删除此记录。有可能吗?

假设对象被包装在一个数组中,如下所示:

var arr = [
    {field: "l0", headerText: "0-22", width: 120},
    {field: "l1", headerText: "23-43", width: 120},
    {field: "l2", headerText: "44-55", width: 120}
]; 
var result = arr.filter(function(obj) {
    return obj.headerText !== "0-22"; // Or whatever value you want to use
});
console.log(result);
您可以这样做:

var arr = [
    {field: "l0", headerText: "0-22", width: 120},
    {field: "l1", headerText: "23-43", width: 120},
    {field: "l2", headerText: "44-55", width: 120}
]; 
var result = arr.filter(function(obj) {
    return obj.headerText !== "0-22"; // Or whatever value you want to use
});
console.log(result);

假设对象包装在数组中,如下所示:

var arr = [
    {field: "l0", headerText: "0-22", width: 120},
    {field: "l1", headerText: "23-43", width: 120},
    {field: "l2", headerText: "44-55", width: 120}
]; 
var result = arr.filter(function(obj) {
    return obj.headerText !== "0-22"; // Or whatever value you want to use
});
console.log(result);
您可以这样做:

var arr = [
    {field: "l0", headerText: "0-22", width: 120},
    {field: "l1", headerText: "23-43", width: 120},
    {field: "l2", headerText: "44-55", width: 120}
]; 
var result = arr.filter(function(obj) {
    return obj.headerText !== "0-22"; // Or whatever value you want to use
});
console.log(result);
for(var i=0;i
for(var i=0;iLook)


这些对象是否包装在数组中?是的,这些是包装的。这可以使用数组的筛选函数获取对象/索引,然后使用
array.splice()将其从数组中删除
这些对象是否封装在数组中?是的,这些对象是封装的。这可以使用数组的筛选函数获取对象/索引,然后使用
array.splice()将其从数组中删除。
如果您在那里描述代码,这将是一个更好的答案!如果您在那里描述代码,这将是一个更好的答案!