说我有以下对象:
var obj = Object {izaalberg: "65", jfm: "276", matcheanauto: "981", matchfullauto: "2525", mcgoncalves: "221"…}
我想将值对象添加到数组X中,所以结果是:
[['izaalberg',65], ['jfm',7 ],['matcheanauto:',981],['matchfullauto',2525],['mcgoncalves',221]...];
答案 0 :(得分:2)
您需要简单的for
循环
var result = [];
for(var i in obj){
result.push([i, obj[i]]);
}
答案 1 :(得分:0)
使用for..in
循环和Array.prototype.push
。
var obj = {
izaalberg: "65",
jfm: "276",
matcheanauto: "981",
matchfullauto: "2525",
mcgoncalves: "221"
};
var arr = [];
for (var k in obj) {
arr.push([k, obj[k]]);
}
console.log(arr)