如何将嵌套对象转移到外部对象?

时间:2016-03-31 13:53:56

标签: javascript lodash

如何将对象移动到包含嵌套对象的外部对象?

{ criteria: 
   { provider: 2,
     providerName: 'CLX_gw0',
     mcc: null,
     mnc: null,
     dial_code: null,
     active: 1 },
  page: 1,
  pageSize: 50 }

我想这样:

{
    provider: 2,
    providerName: 'CLX_gw0',
    mcc: null,
    mnc: null,
    dial_code: null,
    active: 1,
    page: 1,
    pageSize: 50 
}

1 个答案:

答案 0 :(得分:1)

试试这个。你甚至不需要lodash:

const newObj = Object.assign({}, obj, obj.criteria);
delete newObj.criteria;