尝试从数组中的子对象创建数组

时间:2019-04-29 23:37:32

标签: javascript arrays json typescript angular7

我有一个需要删除的顶级数组,我使用的是Angular7,我不确定如何从该数组中拉出子对象。我想摆脱“顶层”级别,这样您就可以拥有带有属性的对象。任何帮助将不胜感激。

{
    "toplevel": [
        {
            "SetName": "name1",
            "description": "blah blah blah",
            "managingEntitySource": "blah blah blah",
            "effectiveDate": "01/01/9999",
            "terminationDate": "01/01/9999",
            "systemEffectiveDate": "01/01/9999",
            "systemTerminationDate": "01/01/9999",
            "comments": "blah blah blah",
            "lastProcessDate": "01/01/9999"
        },
        {
            "SetName": "name2",
            "description": "blah blah blah",
            "managingEntitySource": "blah blah blah",
            "effectiveDate": "01/01/9999",
            "terminationDate": "01/01/9999",
            "systemEffectiveDate": "01/01/9999",
            "systemTerminationDate": "01/01/9999",
            "comments": "blah blah blah",
            "lastProcessDate": "01/01/9999"
        }
    ]
}

这就是我要寻找的东西:

[
        {
            "SetName": "name1",
            "description": "blah blah blah",
            "managingEntitySource": "blah blah blah",
            "effectiveDate": "01/01/9999",
            "terminationDate": "01/01/9999",
            "systemEffectiveDate": "01/01/9999",
            "systemTerminationDate": "01/01/9999",
            "comments": "blah blah blah",
            "lastProcessDate": "01/01/9999"
        },
        {
            "SetName": "name2",
            "description": "blah blah blah",
            "managingEntitySource": "blah blah blah",
            "effectiveDate": "01/01/9999",
            "terminationDate": "01/01/9999",
            "systemEffectiveDate": "01/01/9999",
            "systemTerminationDate": "01/01/9999",
            "comments": "blah blah blah",
            "lastProcessDate": "01/01/9999"
        }
    ]

1 个答案:

答案 0 :(得分:2)

var jsonObject = {
    "toplevel": [
        {
            "SetName": "name1",
            "description": "blah blah blah",
            "managingEntitySource": "blah blah blah",
            "effectiveDate": "01/01/9999",
            "terminationDate": "01/01/9999",
            "systemEffectiveDate": "01/01/9999",
            "systemTerminationDate": "01/01/9999",
            "comments": "blah blah blah",
            "lastProcessDate": "01/01/9999"
        },
        {
            "SetName": "name2",
            "description": "blah blah blah",
            "managingEntitySource": "blah blah blah",
            "effectiveDate": "01/01/9999",
            "terminationDate": "01/01/9999",
            "systemEffectiveDate": "01/01/9999",
            "systemTerminationDate": "01/01/9999",
            "comments": "blah blah blah",
            "lastProcessDate": "01/01/9999"
        }
    ]
};

var innerArray = jsonObject.toplevel;

console.log(innerArray);