简体   繁体   English

创建没有主键 angular 的新对象

[英]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 :(我需要删除父项中的键,例如删除A、B、TEST等。问题是我需要一个可以执行此操作的函数,因为这些值可以是任何值:(

You can use the spread syntax with Object.assign() and Object.values() as follows:您可以将传播语法与Object.assign()Object.values() ,如下所示:

 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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