How to filter different keys in a array and get unique result in angular js

Viewed 170

I'm trying to filter data from the response and remove duplicate items and push the data into an array, my api response goes as below:

{
   "_id":"0",
   "yacht_id":"200",
   "promo_id":"300",
   "blocked_thru":"promotions",
   "dates":"2017-08-23T00:00:00.000Z",
},
{
  "_id":"1",
  "booking_id":{
        "_id":"100",
        "booking_id":"BK163041494",
               },
  "blocked_thru":"booked",
  "dates":"2017-08-30T00:00:00.000Z",
 },
 {
   "_id":"2",
   "booking_id":{
        "_id":"100",
        "booking_id":"BK163041494",
                 },
    "blocked_thru":"booked",
    "dates":"2017-08-30T00:00:00.000Z",
 }

From the above response, if "booking_id" exist in object and "booking_id._id" is same then, I need to filter and push only unique objects to array.

I need a response as below:

{
   "_id":"0",
   "yacht_id":"200",
   "promo_id":"300",
   "blocked_thru":"promotions",
   "dates":"2017-08-23T00:00:00.000Z",
},
{
  "_id":"1",
  "booking_id":{
        "_id":"100",
        "booking_id":"BK163041494",
               },
  "blocked_thru":"booked",
  "dates":"2017-08-30T00:00:00.000Z",
 },

Any Help would be Appreciated. Thanks.

4 Answers
Related