Q:

Iterating through linked objects, how to avoid duplicates

I have an array of objects that are linked together by a unique id.
Something like this:
var nodes    = [];
    nodes[0] = {'id':1,'linksTo':[2,3],'x':1,'y':1};
    nodes[1] = {'id':2,'linksTo':[1],'x':2,'y':1};
    nodes[2] = {'id':3,'linksTo':[1],'x':2,'y':1};

So suppose i was to draw lines between each point in a canvas element that they link to. In the above case i would draw the same line twice, one from id 1 to id 2 and then again from id 2 to id 1. This is not efficient, and in a game loop this will hurt frame rate over time.
My current method is similar to this logic:
 Object.keys(nodes).forEach(function(nodeIndex) {
 nodes[nodeIndex].linksTo.forEach(function(connectedNode) {
    //line move to x,y 
    //line to x2, y2
  });
});

What would be the most effective way to do this as to not hurt frame rate and avoid drawing the same way twice? Remembering that it needs to be efficient for allowing higher frame rates to continue.

A:

You could draw the line only if the first node's id is less than the second node's id.

