Using arrays to create a node and edge connector

thanks for all your help but ive figured it out the solution but not im trying to make each node connect to the nearest grid intersection any idea how i can do that? i think if make an array of all the grid intersections and compare them to the current node that is placed which should do it but im not sure how to structure it.