You could solve this problem using d3.set() method:

The code will be:

var data=[{"code":5222,"date":3-4-2015},{"code":5222,"date":3-6-2015},{"code":5222,"date":3-7-2015},];

var Unique = d3.set(data, function(d) {return d.code});

Unique returns only '5222', as you expected.

Please, note that d3 converts data to strings in this case, so it might be the case you would need to convert them back to numbers.


I think you need to use nest().

var nest = d3.nest()
  .key(function(d) { return d.code; })

That will create a new array with each code only once and an object of all the objects that have that value.


var data=[{"code":5222,"date":3-4-2015},{"code":5222,"date":3-6-2015},{"code":5222,"date":3-7-2015}];

var nest = d3.nest()
  .key(function(d) { return d.code;})
    .text(function(d){ return d.key;})
    .attr("value",function(d){return d.key;});

This code works for me with no errors

Related Query