js怎样把不规律key的对象的key-value分离并重新组合成一个数组

现有数据格式

mapColumnNames: {
   item_code: "商品编码",
   source1_name: "来源1",
   category_name: "大类",
   category2_name: "大类2",
   style_color: "款色号",
   brand_code_name: "品牌",
   item_name: "品名",
   BRCATEGORY1: "经营类目1",
   BRCATEGORY3: "经营类目3",
   BRCATEGORY2: "经营类目2",
   size_name: "尺码名称",
   SALESASPECT: "销售特征",
   brand_group_name: "品牌组",
   SAMESTYLENO: "同款款号",
   SETTLEMENTTYPE: "结算类型",
   PRODUCTYEAR: "预算年",
   source2_name: "来源2",
   style_no: "款号",
   color_name: "颜色名称"
}

需求格式

tableColumn:[
    {
        field: "item_code",
        title: "商品编码"
    },
    {
        field: "source1_name",
        title: "来源1"
    },
    ...
]
阅读 2.2k
1 个回答
const mapColumnNames = {
   item_code: "商品编码",
   source1_name: "来源1",
   category_name: "大类",
   category2_name: "大类2",
   style_color: "款色号",
   brand_code_name: "品牌",
   item_name: "品名",
   BRCATEGORY1: "经营类目1",
   BRCATEGORY3: "经营类目3",
   BRCATEGORY2: "经营类目2",
   size_name: "尺码名称",
   SALESASPECT: "销售特征",
   brand_group_name: "品牌组",
   SAMESTYLENO: "同款款号",
   SETTLEMENTTYPE: "结算类型",
   PRODUCTYEAR: "预算年",
   source2_name: "来源2",
   style_no: "款号",
   color_name: "颜色名称"
};

Object.keys(mapColumnNames)
.map(field =>({ field, title: mapColumnNames[field] }));
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题