let a = [{
label: "英国2号处理中心",
prop: "center",
},
{
label: "美国1号处理中心",
prop: "center",
}, {
label: "法国处理中心",
prop: "center",
},
{
label: "CNY",
prop: "currency",
},
{
label: "USD",
prop: "currency",
},
{
label: "JPY",
prop: "currency",
}
];
let b = [{
center: "英国2号处理中心",
currency: "CNY"
},
{
center: "英国2号处理中心",
currency: "USD"
}, {
center: "英国2号处理中心",
currency: "JPY"
},
{
center: "美国1号处理中心",
currency: "CNY"
},
{
center: "美国1号处理中心",
currency: "USD"
},
{
center: "美国1号处理中心",
currency: "JPY"
}, {
center: "法国处理中心",
currency: "CNY"
}, {
center: "法国处理中心",
currency: "USD"
}, {
center: "法国处理中心",
currency: "JPY"
}
];
如何动态把a数组结构转换成b数组结构?像如果在a数组再添加一个新的prop属性b数组也对应生成。
let arr = [["英国2号处理中心", "英国3号处理中心"],["CNY", "USD"],["a公司", "b公司"]];
let narr = []
arr[0].forEach((item, i) => {
arr[1].forEach(item2 => {
arr[2].forEach(item3 => {
narr.push({
center: item,
currency: item2,
company: item3
});
});
});
});
或者像这条数据,arr数组是动态不确定有几层的,如何动态的循环生成同样的narr数组呢?
第二种没给
key