js 对象扁平化

 const obj = {

    name: 'GoodsStructure',

    path: '/goodsStructure',

    hidden: false,

    redirect: 'noRedirect',

    component: 'Layout',

    alwaysShow: true,

    meta: {

      title: '产品结构清单',

      icon: 'tree',

      noCache: true,

      link: null,

    },

    props: false,

  };

  const getType = (objParams: Object) => {

    const res = {};

    const isObj = (objParams2: Object) => {

      debugger;

      for (const key in objParams2) {

        if (Object.prototype.toString.call(objParams2[key]) == '[object Object]') {

          isObj(objParams2[key]);

        } else {

          res[key] = objParams2[key];

        }

      }

    };

    isObj(objParams);

    return res;

  };

getType (obj)

你可能感兴趣的:(javascript,前端,开发语言,es6,js)