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);
1[
2 { id: 10, color: "red" },
3 { id: 20, color: "blue" },
4 { id: 30, color: "green" }
5].reduce((acc, cur) => ({ ...acc, [cur.color]: cur.id }), {})
6
7//output:
8{red: 10, blue: 20, green: 30}