简体   繁体   中英

Create new object without primary keys angular

I have some object like this

const objectValues = {
    "A": {
        "level": "1"
    },
    "B": {
        "active": "false"
    },
    "TEST": {
        "value": "abc",
        "must": "true"
    },
    "D": {
        "comma": "false",
        "show": "true",
        "use": "false"
    }};

I need to create new object that will look like this

const newObjectValues = {
        "level": "1"
        "active": "false"
        "value": "abc",
        "must": "true"
        "comma": "false",
        "show": "true",
        "use": "false"
    };

I need to remove keys in parent, like to remove A, B, TEST etc.The problem is that i need a function that will do that, because those values can be anything :(

You can use the spread syntax with Object.assign() and Object.values() as follows:

 const objectValues = { "A": { "level": "1" }, "B": { "active": "false" }, "TEST": { "value": "abc", "must": "true" }, "D": { "comma": "false", "show": "true", "use": "false" }}; const result = Object.assign({}, ...Object.values(objectValues)); console.log(result);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM