How can I create a directed graph of strings in JavaScript? <p>I am trying to create a directed graph data structure in JavaScript. I want each node in the graph to be doubly-linked, so that I can obtain a list of links that each node points to, as well as the links that point to that node. Each node is an array with 3 elements, like so: <code>[["node that links to node a"], "node a", ["node that node a links to"]]</code></p> <pre><code>//The functions linkNodes and unlinkNodes should add and remove nodes links from the directed graph, respectively. var nodes = new Object(); function linkNodes(a, b){ //a should be a string, and b should be a string as well //create the node a, if it doesn't exist yet //create the node b, if it doesn't exist yet //link the node a to the node b } function unlinkNodes(){ //unlink the nodes a and b, if a and b exist //create the node a, if it doesn't exist yet } function getNode(string){ //get the node that corresponds to the string //if the string doesn't exist, then return false } </code></pre> <p>jsfiddle: <a href="http://jsfiddle.net/NTKZ9/1/" rel="nofollow">http://jsfiddle.net/NTKZ9/1/</a>​</p> <p>Is there a more concise way to implement a directed graph in JavaScript, besides the one that I've proposed here?</p>