I am currently available for freelance/contract work. Book a meeting so we can talk about your project.

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