@historydev
Острая аллергия на анимешников

Как разбить этот массив на объекты по id?

Доброе утро.У меня есть вот такой массив.
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 } ] ]


Который возвращает мой sql запрос,как мне разбить его на объекты,чтобы каждый юзер был объектом и я мог обратится допустим users.email и мне выпрыгивали все почтовые ящики?

Вот мой запрос

sequelize
  .query('SELECT * FROM users', { raw: true })
  .then(users => {
    console.log(users)
});



Спасибо ^^
  • Вопрос задан
  • 97 просмотров
Решения вопроса 1
TTATPuOT
@TTATPuOT
https://code.patriotovsky.ru/
Дак у вас и так каждый юзер разбит по объектам.
Если вы хотите получить все почтовые ящики из массива пользователей, вы можете использовать:
const allEmails = users.map(user => user.email); //['Jane', 'Jane', 'Jane', ...]
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы