我有以下对象结构
var obj = {"0":"direct","1":"indirect","2":"dir","3":"indir"};
预期输出为:
result = [["direct","indirect"],["indirect","dir"],["dir","indir"]];
我试过的:
var result = [];
var array = [];
for(var key in obj){
if(array.length <2) {
array.push(obj[key]);
}else{
array =[];
array.push(obj[key-1]);
}
if(array.length == 2){
result.push(array);
}
}
console.log(result);
我得到的输出如下:
result = [["direct", "indirect"], ["indirect", "indir"]]