D3.js node.links() Function

The node.links() function returns an array of links to the children of the node object, each link object has a source and a target field that hold references to child nodes.
Syntax:
node.links();
Parameters: This method does not accept any parameters.
Return Values: This method returns an array of links to the children of the node object.
Example 1:
HTML
| <!DOCTYPE html> <html>  Â<head>     <metacharset="utf-8">  Â    <scriptsrc=     </script> </head>  Â<body>     <script>         var data = {             "name":"zambiatek",              "about":"Computer Science Portal",             "children":[                 {"name":"GFG1"},                 {"name":"GFG2"},                 {"name":"GFG3"}             ]         }         var root = d3.hierarchy(data);         a=root.links();         console.log(a);         for (i=0;i<a.length;i++){             console.log(a[i].source.children)         }     </script> </body>  Â</html> | 
Output:
Example 2: Root containing no children return empty links array.
HTML
| <!DOCTYPE html> <html>  Â<head>     <metacharset="utf-8">  Â    <scriptsrc=     </script> </head>  Â<body>     <script>         var data = {"name":"GFG1"}  Â        var root = d3.hierarchy(data);  Â        console.log(root.links());     </script> </body>  Â</html> | 
Output:
 
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					



