0

I'm having a real brain freeze moment here. I have an array of objects that I need to convert into just an array of properties. What would be the best approach to turn this;

[
  {
    user_id: 302
  },
  {
    send_user_email: true
  },
  {
    send_admin_email: true
  }
]

into this;

[
  user_id: 302,
  send_user_email: true,
  send_admin_email: true
]
2
  • 2
    That array doesn't look valid. Commented Feb 12, 2020 at 15:33
  • If you're referring to something like associative arrays in PHP, they don't exist in JavaScript, therefore something like [user_id: 302] is not a valid array in JavaScript. Commented Feb 12, 2020 at 15:35

1 Answer 1

3

You could use Object.assign:

const array = [
  {
    user_id: 302
  },
  {
    send_user_email: true
  },
  {
    send_admin_email: true
  }
];

const result = Object.assign({}, ...array);

console.log(result);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.