SOURCE

var jsObjects = {
  "success": true,
  "code": "200",
  "message": "成功获取产品档案",
  "data": [
    {
      "id": "01",
      "name": "01名称",
      "list": [
        {
          "id": "001",
          "name": "001名称",
          "list": [
            {
              "id": "001",
              "name": "001名称",
              "list": [
                {
                  "id": "01-001-001-001",
                  "name": "01-001-001-001名称",
                  "specification": "01-001-001-001规格",
                  "type": "01-001-001-001型号"
                },
                {
                  "id": "01-001-001-002",
                  "name": "01-001-001-002名称",
                  "specification": "01-001-001-002规格",
                  "type": "01-001-001-002型号"
                }
              ]
            },
            {
              "id": "002",
              "name": "002名称",
              "list": [
                {
                  "id": "01-001-002-001",
                  "name": "01-001-002-001名称",
                  "specification": "01-001-002-001规格",
                  "type": "01-001-002-001型号"
                },
                {
                  "id": "01-001-002-002",
                  "name": "01-001-002-002名称",
                  "specification": "01-001-002-002规格",
                  "type": "01-001-002-002型号"
                }
              ]
            }
          ]
        },
        {
          "id": "002",
          "name": "002名称",
          "list": [
            {
              "id": "001",
              "name": "001名称",
              "list": [
                {
                  "id": "01-002-001-001",
                  "name": "01-002-001-001名称",
                  "specification": "01-002-001-001规格",
                  "type": "01-002-001-001型号"
                },
                {
                  "id": "01-002-001-002",
                  "name": "01-002-001-002名称",
                  "specification": "01-002-001-002规格",
                  "type": "01-002-001-002型号"
                }
              ]
            },
            {
              "id": "002",
              "name": "002名称",
              "list": [
                {
                  "id": "01-002-002-001",
                  "name": "01-002-002-001名称",
                  "specification": "01-002-002-001规格",
                  "type": "01-002-002-001型号"
                },
                {
                  "id": "01-002-002-002",
                  "name": "01-002-002-002名称",
                  "specification": "01-002-002-002规格",
                  "type": "01-002-002-002型号"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "id": "02",
      "name": "02名称",
      "list": [
        {
          "id": "001",
          "name": "001名称",
          "list": [
            {
              "id": "001",
              "name": "001名称",
              "list": [
                {
                  "id": "02-001-001-001",
                  "name": "02-001-001-001名称",
                  "specification": "02-001-001-001规格",
                  "type": "02-001-001-001型号"
                },
                {
                  "id": "02-001-001-002",
                  "name": "02-001-001-002名称",
                  "specification": "01-001-001-002规格",
                  "type": "02-001-001-002型号"
                }
              ]
            },
            {
              "id": "002",
              "name": "002名称",
              "list": [
                {
                  "id": "02-001-002-001",
                  "name": "02-001-002-001名称",
                  "specification": "02-001-002-001规格",
                  "type": "02-001-002-001型号"
                },
                {
                  "id": "02-001-002-002",
                  "name": "02-001-002-002名称",
                  "specification": "02-001-002-002规格",
                  "type": "02-001-002-002型号"
                }
              ]
            }
          ]
        },
        {
          "id": "002",
          "name": "002名称",
          "list": [
            {
              "id": "001",
              "name": "001名称",
              "list": [
                {
                  "id": "02-002-001-001",
                  "name": "02-002-001-001名称",
                  "specification": "02-002-001-001规格",
                  "type": "02-002-001-001型号"
                },
                {
                  "id": "02-002-001-002",
                  "name": "02-002-001-002名称",
                  "specification": "02-002-001-002规格",
                  "type": "02-002-001-002型号"
                }
              ]
            },
            {
              "id": "002",
              "name": "002名称",
              "list": [
                {
                  "id": "02-002-002-001",
                  "name": "02-002-002-001名称",
                  "specification": "02-002-002-001规格",
                  "type": "02-002-002-001型号"
                },
                {
                  "id": "02-002-002-002",
                  "name": "02-002-002-002名称",
                  "specification": "02-002-002-002规格",
                  "type": "02-002-002-002型号"
                }
              ]
            }
          ]
        }
      ]
    }
  ]
};

/* 参数
* array 树结构 查找所有叶子节点
*/
function parseTreeJson(array) {
    for (let index = 0; index < array.length; index++) {
        const element = array[index];
        // 判断element.children是对象
        if (element.list && typeof (element.list) == 'object') {
            parseTreeJson(element.list)
        } else {
            // 判断是否为子节点
            if (! (element.list || typeof (element.children) == 'array')) {
                // 获得符合的 node
                nodes.push(element);
            }
        }
    }
}

var nodes = [];
parseTreeJson(jsObjects.data);
console.log(nodes)
console 命令行工具 X clear

                    
>
console