对象数组有最多三层结构,最外层对象数组、children内嵌套对象数组、嵌套数组内children嵌套的对象数组,即如下的arr。
别人问的问题,傻瓜解法。循环遍历,push方法即可将子级放进父级中。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>