我正在使用
将Json对象转换为数组var ticks= {firstkey: "firstvalue", secondkey: "secondvalue", thirdkey: "thirdValue"}
var arr = $.map(ticks, function(value, index) {
return [[index,value]];
});
将输出作为
0:[“ firstkey”,“ firstvalue”] 1:[“ secondkey”,“ secondvalue”] 2:[““ thirdkey”,“ thirdValue”]
我想要的结果
FirstKey:FirstValue SecondKey:SecondValue ThirdKey:ThirdValue
关联数组形式
答案 0 :(得分:0)
您可以遍历对象并相应地推送到数组。希望这会有所帮助
var ticks= {firstkey: "firstvalue", secondkey: "secondvalue", thirdkey: "thirdValue"};
var arr = Array();
for (var tick in ticks) {
arr.push({[tick]:ticks[tick]});
}
console.log(arr[0]);
console.log(arr[2].thirdkey);