How to convert an array of key-value tuples into an object

后端 未结 15 1910
南方客
南方客 2020-12-07 20:11

I have an array:

[ [ \'cardType\', \'iDEBIT\' ],
  [ \'txnAmount\', \'17.64\' ],
  [ \'txnId\', \'20181\' ],
  [ \'txnType\', \'Purchase\' ],
  [ \'txnDate\         


        
15条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 20:30

    Short ES6 way with Airbnb code style

    Exemple:

    const obj = arr.reduce((prevObj, [key, value]) => ({ ...prevObj, [key]: value }), {});
    

提交回复
热议问题