I want to seperate json array elements based on their duplication

Viewed 20

I want to seperate elements both duplicated and non duplicated into seperate array as shown below:

Input :

let test = [
 {
  "id1": "1"
 },
 {
  "id1": "2"
 },
 {
  "id1": "2"
 }
]

output:

ans1 = [
 {
  "id1": "1"
 }
]

ans2 = [
 {
  "id1": "2"
 },
 {
  "id1": "2"
 }
]

I have tried using for loop but i was not able to find answer and now I am trying to use other methods of array.

0 Answers
Related