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

问题描述 投票:0回答:1

我有一个数组,我需要摆脱顶级,我使用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"
        }
    ]
javascript arrays json typescript angular7
1个回答
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);
© www.soinside.com 2019 - 2024. All rights reserved.