-7
var arr = [['name', 'Sơn Đặng'], ['age', 18]]

console.log(arrToObj(arr))

Expected output:

{ name: 'Sơn Đặng', age: 18 }

How to make the above two arrays into one object containing both into one?

Andy
  • 53,323
  • 11
  • 64
  • 89
  • You need a function that accepts an array (of arrays), and then you can use [iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration#for...of_statement) to loop over the nested arrays to build your object, and then return it from the function. – Andy Jun 01 '22 at 15:00
  • `Object.fromEntries([['name', 'Sơn Đặng'], ['age', 18]])` – epascarello Jun 01 '22 at 15:12

0 Answers0