0

I have this object:

const object = {
  profile: {
    name: "John",
    lastName: "Doe"
  },
  email: "johndoe@email.com",
  address: {
    street: "Street J",
    numero: 123
  },
  role: "admin"
};

How can I make it flat? So all the data is in the root of the object? To look like this:

const object = {
  name: "John",
  lastName: "Doe"
  email: "johndoe@email.com",
  street: "Street J",
  numero: 123
  role: "admin"
};

I've been breaking my head but can't achieve what I need. Also I don't know if there will be nested objects, it may. I've tried using Object.entries and trying to run over the array but it's not working.

Thanks

MrRobot
  • 1,001
  • 1
  • 14
  • 34

0 Answers0