Here is the structure:

const msg={
  razd: {
    one: {
      category:[{
       "_id": 1,"cat_name":"tst"
      }, {
       "_id": 2,"cat_name":"goo"
      }, {
       "_id": 4,"cat_name":"hoo"
      },
      ]},
    two: {
      category:[{
       "_id": 7,"cat_name":"hoo"
      }, {
       "_id": 9,"cat_name":"bar"
      },]
    }
  }};


Here is a list of _id that need to be filtered:
const expect=[4, 7]

Expected result:
[{"_ id": 4,"cat_name":"hoo"}, {"_id": 7,"cat_name":"hoo"}}

How to do it in a fashionable way?

1 Answers 1

[].concat(...Object.values ​​(msg.razd) .map(n=>n.category)).filter(n=>expect.includes( n._id))

or

Object.values ​​(msg.razd) .flatMap(n=>n.category) .filter(n=>expect.includes(n._id))
  • Thank you!
    What a beauty, and even in one line.
    – Chinese Paintball May 18 '19 at 14:50