D
D
Dmitry2019-11-15 19:28:11
JavaScript
Dmitry, 2019-11-15 19:28:11

How to filter one array depending on another array of arrays?

Hello, I have an array of objects like this:

[
    {
      id: 1,
      name: '1'
    },
    {
      id: 2,
      name: '3'
    },
    {
      id: 2,
      name: '3'
    }
  ]

and such an array of arrays with objects:
[
    [
      {
        id: 1,
        name: '1'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 1,
        name: '1'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 1,
        name: '1'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 2,
        name: '3'
      }
    ],
    [
      {
        id: 1,
        name: '1'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 1,
        name: '1'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 1,
        name: '1'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 2,
        name: '3'
      }
    ],
    [
      {
        id: 1,
        name: '1'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 1,
        name: '1'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 1,
        name: '1'
      },
      {
        id: 2,
        name: '3'
      },
      {
        id: 2,
        name: '3'
      }
    ]
  ]

Array 1 depends on the data in array 2 and it is necessary that if the second and first arrays have the same id from objects, then filter the first array by it

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question