Skip to content
Related Articles

Related Articles

D3.js node.children Property
  • Last Updated : 23 Sep, 2020

The node.children property in D3.js returns an array of child nodes (null for leaf nodes and undefined for nodes having no child).

Syntax:

node.children

Return Value: This property returns an array of child nodes (null for leaf nodes and undefined for nodes having no child).

Example 1:

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
  
    <script src=
        "https://d3js.org/d3.v5.min.js">
    </script>
</head>
  
<body>
    <script>
        var data = {
            "name":"GeeksforGeeks", 
            "about":"Computer Science Portal",
            "children":[{"name":"GFG"}]
        }
        var root = d3.hierarchy(data);
        console.log(root.children);
    </script>
</body>
  
</html>

chevron_right


Output:



Example 2: In this example, this method returns undefined as the root node has no child node.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
  
    <script src=
        "https://d3js.org/d3.v5.min.js">
    </script>
</head>
  
<body>
    <script>
        var data = {"name":"GFG1"}
  
        var root = d3.hierarchy(data);
  
        console.log(root.children);
    </script>
</body>
  
</html>

chevron_right


Output:

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :