-2

enter image description here

  1. I don't want to change the original sequence of Objects in an array.
  2. But I need to get the items in sequence when the location and place are equal.
  3. I tried but I need for an and condition.

        var sim=[{name:"vinod",location:"asia",place:"simha"},{name:"ajay",location:"zyd", place:"aaa"},{name:"ram",location:"raj",place:"zzz"},
{name:"abhirma",location:"zyd",place:"aaa"},
{name:"ram",location:"raj",place:"zzz"}];

    
    sim.sort(function(a, b){
      return a.location.localeCompare(b.location);
    });
    console.log(sim);
user3686794
  • 79
  • 1
  • 9

1 Answers1

0
const unique = new Set(sim.map(a=> JSON.stringify(a)));
console.log(unique);  
const newarr= Array.from(unique).map(b=>JSON.parse(b));
console.log(newarr)

variable "unique " will be return the unique value and removed the duplicated value and variable "newarr" will return the array of object

vinoth s
  • 178
  • 6