0

I have one JSON array. I need a unique array. I have tried all possible things using .map(), .filter(). but no success.

Also, I have applied alternatives but it does not work for me. such as

How to get distinct values from an array of objects in JavaScript?

How to make a JSON array unique

var slots = [
    {
        id: 1239,
        slot1: "08:00:00-16:00:00",
        slot2: null,
        slot3: null,
        slot4: null,
        slot5: null,
        slot6: null,
        slot7: null,
        slot8: null,
        slot9: null,
        slot10: null,
        slot11: null,
        slot12: null,
        slot13: null,
        slot14: null,
        slot15: null,
        slot16: null,
        slot17: null,
        slot18: null,
        slot19: null,
        slot20: null,
        slots_end: "2021-07-06T16:00:00+03:00",
        slots_start: "2021-07-06T08:00:00+03:00",
    },
    {
        id: 1240,
        slot1: "09:00:00-18:00:00",
        slot2: null,
        slot3: null,
        slot4: null,
        slot5: null,
        slot6: null,
        slot7: null,
        slot8: null,
        slot9: null,
        slot10: null,
        slot11: null,
        slot12: null,
        slot13: null,
        slot14: null,
        slot15: null,
        slot16: null,
        slot17: null,
        slot18: null,
        slot19: null,
        slot20: null,
        slots_end: "2021-07-06T18:00:00+03:00",
        slots_start: "2021-07-06T09:00:00+03:00",
    },
    {
        id: 1241,
        slot1: "09:00:00-18:00:00",
        slot2: null,
        slot3: null,
        slot4: null,
        slot5: null,
        slot6: null,
        slot7: null,
        slot8: null,
        slot9: null,
        slot10: null,
        slot11: null,
        slot12: null,
        slot13: null,
        slot14: null,
        slot15: null,
        slot16: null,
        slot17: null,
        slot18: null,
        slot19: null,
        slot20: null,
        slots_end: "2021-07-06T18:00:00+03:00",
        slots_start: "2021-07-06T09:00:00+03:00",
    },
]

As a result, should be...

enter image description here

Thanks in advance.

10
  • unique json array? what u r looking for.. Commented Jul 6, 2021 at 9:35
  • how you are deciding the uniqueness of array ? comparing all the array values or some specific keys ? Commented Jul 6, 2021 at 9:36
  • @Muhammad Atif Akram, the keys will same, I want a unique Object by value. Commented Jul 6, 2021 at 9:43
  • 1
    question is unclear. Commented Jul 6, 2021 at 9:55
  • 1
    Just mention on what base you will decide the uniqueness of array . If you want to compare all the properties then each object will be unique since each object has unique id. So decide first which properties you need to compare to get the unique array Commented Jul 6, 2021 at 10:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.