Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

D3.js node.depth Property

  • Last Updated : 23 Sep, 2020

The D3.js node.depth property returns the length of the path from the node up to the root.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

node.depth

Return Value: This property returns the length of the path from the node up to the root.

Example 1:



HTML




<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
  
    <script src=
    </script>
</head>
  
<body>
    <script>
        var data = {
            "name":"GeeksforGeeks", 
            "about":"Computer Science Portal",
            "children":[
                {"name":"GFG1"},
                {"name":"GFG2"},
                {"name":"GFG3"},
                {"name":"GFG4"}
            ]
        }
        var root = d3.hierarchy(data);
        console.log(root.children[0].depth);
    </script>
</body>
  
</html>

Output:

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

HTML




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

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :