I have some objects in array with coordinates.
var players = [
{x:100, y:100, pid:1},
{x:-100, y:200, pid:2},
{x:600, y:1200, pid:3}
]
var mousepos = {x:50, y:0}
var selected = null
And I want to calculate which of these objects have closest coordinates to mousepos to select it pid
selected = pid of closest coords to mousepos
if anyone could give me easy done code?