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.

4
  • "the solution provided deletes the key and give array of lenght 3" Which one? There are multiple solutions in the linked question. Commented May 13, 2021 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. Commented May 13, 2021 at 10:31
  • 1
    @rED, Here is your exact solution codepen.io/Maniraj_Murugan/pen/VwpeNNZ Commented May 13, 2021 at 10:32
  • 1
    ...I don't believe that? That's the second solution. Commented May 13, 2021 at 10:32

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.