D3: use d3.max to get containing object?
问题 I have the following data, an array of objects: var data = [ { x: 0, y0: 0, y: 100 }, { x: 1, y0: 0, y: 150 }, { x: 2, y0: 50, y: 100 }, { x: 3, y0: 50, y: 150 } ] I'd like to find the object with the biggest discrepancy between y and y0 , using D3. I can do this to get the biggest difference: var max_val = d3.max(data, function(d) { return d.y - d.y0;} ); It returns 150. But what I don't know how to do is get the containing object, and learn that the corresponding value of x is 1. Any ideas?