Sunday, September 22, 2024
Google search engine
HomeLanguagesJavascriptD3.js node.depth Property

D3.js node.depth Property

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

Syntax:

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=
        "https://d3js.org/d3.v5.min.js">
    </script>
</head>
  
<body>
    <script>
        var data = {
            "name":"neveropen", 
            "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=
        "https://d3js.org/d3.v5.min.js">
    </script>
</head>
  
<body>
    <script>
        var data = {"name":"GFG1"}
  
        var root = d3.hierarchy(data);
  
        console.log(root.depth);
    </script>
</body>
  
</html>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!

RELATED ARTICLES

Most Popular

Recent Comments