1var obj = {"1":5,"2":7,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0}
2var result = Object.keys(obj).map(function(key) {
3 return [Number(key), obj[key]];
4});
5
6console.log(result);
1//ES6 Object to Array
2
3const numbers = {
4 one: 1,
5 two: 2,
6};
7
8console.log(Object.values(numbers));
9// [ 1, 2 ]
10
11console.log(Object.entries(numbers));
12// [ ['one', 1], ['two', 2] ]
1//Supposing fooObj to be an object
2
3fooArray = Object.entries(fooObj);
4
5fooArray.forEach(([key, value]) => {
6 console.log(key); // 'one'
7 console.log(value); // 1
8})
9
1var object = {'Apple':1,'Banana':8,'Pineapple':null};
2//convert object keys to array
3var k = Object.keys(object);
4//convert object values to array
5var v = Object.values(object);
1var obj = {"1":5,"2":7,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0}
2var result = Object.keys(obj).map((key) => [Number(key), obj[key]]);
3
4console.log(result);
1const array = [
2 ['key', 1],
3 ['two', 2],
4];
5
6Object.fromEntries(array);
7// { one: 1, two: 2 }
8