【发布时间】:2019-05-17 05:09:03
【问题描述】:
我有一个状态对象数组。我想将数组中的值转换成键值对
所以,我的状态是这样的:
0: {emp_code: "a001", company_code: "company_a", name: "abx", details: Array(3), details_dtypes: Array(3)}
1: {emp_code: "b002", company_code: "company_b", name: "xbz ", details: Array(2), details_dtypes: Array(2)}
//and so on adding other values to the array
我想把emp-code和company_code转换成键值对,像JSON对象一样显示; 所以 JSON 输出看起来像这样:
{
emp_and_company:
{
"company_a" : ["a001","a002"],
"company_b" : ["b002","b003"]
}
}
所以我只想将 company_code 作为键,将值作为 emp_code
【问题讨论】:
-
你从哪里得到
a002和b003? -
@brk from // 等等评论
标签: javascript json reactjs state