Building objects from nested arrays

Posted on

We can turn nested arrays of key-value-pairs into an object with Object.fromEntries().

const pairs = [
  ["name", "Bob"],
  ["occupation", "Fry cook"],
  ["shape", "rectangular"]
]
 
Object.fromEntries(pairs)
// ⇒ {
//     name: "Bob",
//     occupation: "Fry cook",
//     shape: "rectangular"
//   }
const pairs = [
  ["name", "Bob"],
  ["occupation", "Fry cook"],
  ["shape", "rectangular"]
]
 
Object.fromEntries(pairs)
// ⇒ {
//     name: "Bob",
//     occupation: "Fry cook",
//     shape: "rectangular"
//   }
Debug
none
Grid overlay