-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]...];
1
  • just for loop, and i sure this duplicated question Commented Jun 1, 2015 at 14:55

2 Answers 2

2

You need simple for loop like

var result = [];
for(var i in obj){
    result.push([i, obj[i]]);
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, finally I find an answers ;)
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)
            

1 Comment

it's very simple thanks I find an answers ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.