Home  >  Q&A  >  body text

javascript - How to traverse the tree structure json of N-level child nodes to determine that the length of the deepest children is 0?

data= {

    "name": "root",
        "size": "4",
        "Rate": "4",
        "level": "3",
        "children": [
    {
        "name": "C1",
        "size": "8",
        "Rate": "8",
        "level": "4",
        "children": [
            {
                "name": "C11",
                "size": "8",
                "Rate": "8",
                "level": "5",
                "children":[]
            }
        ]
    }
]
}
PHP中文网PHP中文网2686 days ago789

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-06-12 09:26:12

    js judgment? ?

    Use hasownproperty('children') to encapsulate whether the node contains children

    Then traverse or while judgment, if there are no children at this time, it is the end, and then judge it

    reply
    0
  • Cancelreply