我有如下的对象结构
var obj = {
a : 1,
b : [x,y,z],
c : [0,1,3],
d : ['%','-','+']
}
我想将该对象转换为以下格式
{
1 : {
x : {
0 : ['%','-','+'], // Last index remains as an array
1 : ['%','-','+'],
3 : ['%','-','+']
},
y : {
0 : ['%','-','+'], // Last index remains as an array
1 : ['%','-','+'],
3 : ['%','-','+']
},
z : {
0 : ['%','-','+'], // Last index remains as an array
1 : ['%','-','+'],
3 : ['%','-','+']
}
}
}
['%','-','+']
如果在上述情况下还有一个属性,则继续相同的过程。
var v = {}/* Object of above */, keys = Object.keys(v), simplifiedColumns = {};
for (var i = 0, l = keys.length; i < l ; i++) {
if (v[i] instanceof Array) {
}else{
simplifiedColumns[keys[i]] = simplifiedColumns[keys[i]] || {};
}
}
请建议我完成这个逻辑。