0

So i have two array and i want to sort the array with, Also i dont want to delete unqiue keys, the solution provided deletes the key and give array of lenght 3.:

const data = [
  {
    id: '111',
    user: '178'
  },
  {
    id: '222',
    user: '180'
  },
  {
    id: '333',
    user: '186'
  },
  {
    id: '112',
    user: '180'
  }
]
const someUser = ['180', '186', '178']

And i want output as:

[
  {
    id: '222',
    user: '180'
  },
  {
    id: '112',
    user: '180'
  },
  {
    id: '333',
    user: '186'
  },
  {
    id: '111',
    user: '178'
  }
]

If we run a map or forEach loop, i want to get array of object according to the user field. Like if user 180 has 2 fields in data then i want first array with 2 objects of user containing 180.

Ashishssoni
  • 729
  • 4
  • 14
  • "*the solution provided deletes the key and give array of lenght 3*" Which one? There are multiple solutions in the linked question. – VLAZ May 13 '21 at 10:28
  • tried 4-5 of them, they removed similar keys and give results in array of length 3, what i want is array of length 4. – Ashishssoni May 13 '21 at 10:31
  • 1
    @rED, Here is your exact solution https://codepen.io/Maniraj_Murugan/pen/VwpeNNZ – Maniraj Murugan May 13 '21 at 10:32
  • 1
    ...[I don't believe that](https://jsbin.com/ruzokak/1/edit?js,console)? That's the second solution. – VLAZ May 13 '21 at 10:32

0 Answers0