V
V
Vladimir2019-10-19 07:04:55
MySQL
Vladimir, 2019-10-19 07:04:55

How to split this array into objects by id?

Good morning. I have an array like this.

spoiler

[ [ TextRow {
      id: 1,
      email: 'John',
      password: 'Hancock',
      createdAt: 2019-10-19T03:46:36.000Z,
      updatedAt: 2019-10-19T03:46:36.000Z },
    TextRow {
      id: 2,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:47:36.000Z,
      updatedAt: 2019-10-19T03:47:36.000Z },
    TextRow {
      id: 3,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:47:51.000Z,
      updatedAt: 2019-10-19T03:47:51.000Z },
    TextRow {
      id: 4,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:51:16.000Z,
      updatedAt: 2019-10-19T03:51:16.000Z },
    TextRow {
      id: 5,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:52:00.000Z,
      updatedAt: 2019-10-19T03:52:00.000Z },
    TextRow {
      id: 6,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:53:09.000Z,
      updatedAt: 2019-10-19T03:53:09.000Z },
    TextRow {
      id: 7,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:53:23.000Z,
      updatedAt: 2019-10-19T03:53:23.000Z },
    TextRow {
      id: 8,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:53:41.000Z,
      updatedAt: 2019-10-19T03:53:41.000Z },
    TextRow {
      id: 9,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:53:56.000Z,
      updatedAt: 2019-10-19T03:53:56.000Z },
    TextRow {
      id: 10,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:54:21.000Z,
      updatedAt: 2019-10-19T03:54:21.000Z },
    TextRow {
      id: 11,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:54:35.000Z,
      updatedAt: 2019-10-19T03:54:35.000Z },
    TextRow {
      id: 12,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:55:48.000Z,
      updatedAt: 2019-10-19T03:55:48.000Z },
    TextRow {
      id: 13,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:57:10.000Z,
      updatedAt: 2019-10-19T03:57:10.000Z },
    TextRow {
      id: 14,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:57:32.000Z,
      updatedAt: 2019-10-19T03:57:32.000Z },
    TextRow {
      id: 15,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:57:50.000Z,
      updatedAt: 2019-10-19T03:57:50.000Z },
    TextRow {
      id: 16,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:59:22.000Z,
      updatedAt: 2019-10-19T03:59:22.000Z } ],
  [ TextRow {
      id: 1,
      email: 'John',
      password: 'Hancock',
      createdAt: 2019-10-19T03:46:36.000Z,
      updatedAt: 2019-10-19T03:46:36.000Z },
    TextRow {
      id: 2,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:47:36.000Z,
      updatedAt: 2019-10-19T03:47:36.000Z },
    TextRow {
      id: 3,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:47:51.000Z,
      updatedAt: 2019-10-19T03:47:51.000Z },
    TextRow {
      id: 4,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:51:16.000Z,
      updatedAt: 2019-10-19T03:51:16.000Z },
    TextRow {
      id: 5,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:52:00.000Z,
      updatedAt: 2019-10-19T03:52:00.000Z },
    TextRow {
      id: 6,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:53:09.000Z,
      updatedAt: 2019-10-19T03:53:09.000Z },
    TextRow {
      id: 7,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:53:23.000Z,
      updatedAt: 2019-10-19T03:53:23.000Z },
    TextRow {
      id: 8,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:53:41.000Z,
      updatedAt: 2019-10-19T03:53:41.000Z },
    TextRow {
      id: 9,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:53:56.000Z,
      updatedAt: 2019-10-19T03:53:56.000Z },
    TextRow {
      id: 10,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:54:21.000Z,
      updatedAt: 2019-10-19T03:54:21.000Z },
    TextRow {
      id: 11,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:54:35.000Z,
      updatedAt: 2019-10-19T03:54:35.000Z },
    TextRow {
      id: 12,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:55:48.000Z,
      updatedAt: 2019-10-19T03:55:48.000Z },
    TextRow {
      id: 13,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:57:10.000Z,
      updatedAt: 2019-10-19T03:57:10.000Z },
    TextRow {
      id: 14,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:57:32.000Z,
      updatedAt: 2019-10-19T03:57:32.000Z },
    TextRow {
      id: 15,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:57:50.000Z,
      updatedAt: 2019-10-19T03:57:50.000Z },
    TextRow {
      id: 16,
      email: 'Jane',
      password: 'Doe',
      createdAt: 2019-10-19T03:59:22.000Z,
      updatedAt: 2019-10-19T03:59:22.000Z } ] ]

Which returns my sql query, how do I break it into objects so that each user is an object and I can access let's say users.email and all mailboxes jump out to me?
Here is my request
sequelize
  .query('SELECT * FROM users', { raw: true })
  .then(users => {
    console.log(users)
});


Thanks ^^

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Neverov, 2019-10-19
@HistoryART

Duck you and so each user is divided into objects.
If you want to get all mailboxes from an array of users, you can use:

const allEmails = users.map(user => user.email); //['Jane', 'Jane', 'Jane', ...]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question