-2

Say I have the following object:

var obj = Object {izaalberg: "65", jfm: "276", matcheanauto: "981", matchfullauto: "2525", mcgoncalves: "221"…}

I want to add the values object into array X amount of times so the result is:

[['izaalberg',65], ['jfm',7 ],['matcheanauto:',981],['matchfullauto',2525],['mcgoncalves',221]...];
kakame91
  • 97
  • 1
  • 10

2 Answers2

2

You need simple for loop like

var result = [];
for(var i in obj){
    result.push([i, obj[i]]);
}
Grundy
  • 13,356
  • 3
  • 35
  • 55
0

Use a for..in loop, and 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)
            
Oka
  • 23,367
  • 6
  • 42
  • 53