1

I need get a unique value from an object of array. Forexample i have a following data,

   var empDetails =[
{"name":"dinesh","age":"24","companyName":"ABC","designation":"developer"},
{"name":"dinesh","age":"24","companyName":"ABC","designation":"developer"},{"name":"dinesh","age":"24","companyName":"ABC","designation":"TestEngr"},
{"name":"Ramesh","age":"24","companyName":"ABC","designation":"developer"}];

from this object i want to get the unique array details. output should be like following:

uniqueDet = [
{"name":"dinesh","age":"24","companyName":"ABC","designation":"developer"},
 {"name":"dinesh","age":"24","companyName":"ABC","designation":"TestEngr"},
    {"name":"Ramesh","age":"24","companyName":"ABC","designation":"developer"}]

Based on companyname and designation i want to get the unique details. Can you kindly give me solution to resolve this. Thanks in advance.

Dhinesh.B
  • 461
  • 4
  • 10
  • 20
  • Just use a deduplication implementation that uses an explicit comparison of elements, and then use your custom comparison (by two properties) there. – Bergi Mar 01 '16 at 18:37
  • i dont want to use any libraries... i wanted to implement by using javascript only.. I tried to implement it by iteration .. Is there any other gud way to do ... – Dhinesh.B Mar 01 '16 at 18:42
  • I did not say you needed to use a library. – Bergi Mar 01 '16 at 18:48

1 Answers1

0
var uniqueDet = empDetails.filter(function(x, i) {
    return empDetails.map(function(e) { 
        return JSON.stringify(e)
     }).indexOf(JSON.stringify(x)) == i;
});
isvforall
  • 8,768
  • 6
  • 35
  • 50