对象转数组对象:
const input = {
"2": "黑色",
"7": "LENOVO白蓝",
"8": "1*1,5000次,前≥115°,后≥105°"
};
const output = [];
for (let key in input) {
const value = input[key];
const item = {
confId: parseInt(key),
fieldValue: value
};
output.push(item);
}
console.log(output);
数组对象转对象:
const input = [
{
confId: 2,
fieldValue: "黑色"
},
{
confId: 7,
fieldValue: "LENOVO白蓝"
},
{
confId: 8,
fieldValue: "1*1,5000次,前≥115°,后≥105°"
}
];
const output = {};
for (let item of input) {
const key = String(item.confId);
const value = item.fieldValue;
output[key] = value;
}
console.log(output);