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);
1const names = ['Alex', 'Bob', 'Johny', 'Atta'];
2
3// convert array to th object
4const obj = Object.assign({}, names);
5
6// print object
7console.log(obj);
8
9// {0: "Alex", 1: "Bob", 2: "Johny", 3: "Atta"}
10
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);
1const convertArrayToObject = (array, key) =>
2 array.reduce(
3 (obj, item) => ({
4 ...obj,
5 [item[key]]: item
6 }),
7 {}
8 );
9
1const array = [ [ 'cardType', 'iDEBIT' ],
2 [ 'txnAmount', '17.64' ],
3 [ 'txnId', '20181' ],
4 [ 'txnType', 'Purchase' ],
5 [ 'txnDate', '2015/08/13 21:50:04' ],
6 [ 'respCode', '0' ],
7 [ 'isoCode', '0' ],
8 [ 'authCode', '' ],
9 [ 'acquirerInvoice', '0' ],
10 [ 'message', '' ],
11 [ 'isComplete', 'true' ],
12 [ 'isTimeout', 'false' ] ];
13
14const obj = Object.fromEntries(array);
15console.log(obj);
1const names = ['Alex', 'Bob', 'Johny', 'Atta'];
2
3const obj = Object.assign({}, names);