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.

freedomn-m
  • 27,664
  • 8
  • 35
  • 57
Mitesh Rathod
  • 879
  • 5
  • 18
  • unique json array? what u r looking for.. – Negi Rox Jul 06 '21 at 09:35
  • how you are deciding the uniqueness of array ? comparing all the array values or some specific keys ? – Muhammad Atif Akram Jul 06 '21 at 09:36
  • @Muhammad Atif Akram, the keys will same, I want a unique Object by value. – Mitesh Rathod Jul 06 '21 at 09:43
  • 1
    question is unclear. – Negi Rox Jul 06 '21 at 09:55
  • @Negi Rox, My question is, I have a JSON array. as I have added in the question. So, I need a unique JSON object in the array. – Mitesh Rathod Jul 06 '21 at 10:00
  • FYI there's no JSON in this question. See [What are the differences between JSON and JavaScript object?](https://stackoverflow.com/questions/3975859/what-are-the-differences-between-json-and-javascript-object) – freedomn-m Jul 06 '21 at 10:01
  • Your "as a result" screenshot looks to be *exactly* the same as your source array. What am I missing from the fuzzy screenshot? – freedomn-m Jul 06 '21 at 10:02
  • 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 – Muhammad Atif Akram Jul 06 '21 at 10:05
  • Does this answer your question? [Remove similar objects from array](https://stackoverflow.com/questions/36909866/remove-similar-objects-from-array) – freedomn-m Jul 06 '21 at 10:10
  • @MiteshRathod I'm not sure what you want but try: let something = new Set([...slots]); – Costa Jul 06 '21 at 11:00

0 Answers0