Javascript 如何使用es6从现有对象创建新对象

Javascript 如何使用es6从现有对象创建新对象,javascript,object,ecmascript-6,Javascript,Object,Ecmascript 6,我必须从obj1创建obj2obj1可以有无限的嵌套层。 如何使用es6函数进行创建 我试过Object.keys(obj.forEach)等。我不确定我是否理解。我做错了什么事 我有这个对象(属性键有太多子键,如电话、地址等) 我需要这个 const obj2 = { Person:{ Name:{ type: "input" }, Surname:{ type: "input" } },

我必须从
obj1
创建
obj2
obj1
可以有无限的嵌套层。 如何使用es6函数进行创建

我试过Object.keys(obj.forEach)等。我不确定我是否理解。我做错了什么事

我有这个对象(属性键有太多子键,如电话、地址等)

我需要这个

const obj2 = {
    Person:{
      Name:{
        type: "input"
      },
      Surname:{
        type: "input"
      }
    },
    General:{
      height:{
        type: "number"
      }
      Nested: {
        Nested1: {
          type: "textarea"
        },
        Nested2: {
          type: "textarea"
        }
      }
    }
};

在检查对象时,可以采用迭代和递归的方法

函数构建(源、目标){
if(source.type==='object'){
Object.key(source.properties).forEach(函数(k){
构建(source.properties[k],target[k]={});
});
}否则{
target.type=source.uiType;
}
回报目标;
}
var object={type:“object”,properties:{Person:{title:”,type:“object”,properties:{Name:{type:“string”,uiType:“input”},姓氏:{type:“string”,uiType:“input”},},General:{title:,type:“object”,properties:{height:{type:{type:“string”,uiType:“number”},嵌套:{title:'object Nested1:{type:“string”,uiType:“textarea”},Nested2:{type:“string”,uiType:“textarea”},
结果=生成(对象,{});
console.log(结果);

。作为控制台包装{max height:100%!important;top:0;}
非常感谢,可以使用reduce而不是forEach来完成吗?
const obj2 = {
    Person:{
      Name:{
        type: "input"
      },
      Surname:{
        type: "input"
      }
    },
    General:{
      height:{
        type: "number"
      }
      Nested: {
        Nested1: {
          type: "textarea"
        },
        Nested2: {
          type: "textarea"
        }
      }
    }
};