SOURCE

const data = [
    {
        "id": "f1b055b9-d5cf-4f3f-a43b-481d7c18014f",
        "text": "220kV",
        "nodes": [
            {
                "id": "6469f87b-0f96-454f-bf2c-09c0bca5dc07",
                "voltageClass": "f1b055b9-d5cf-4f3f-a43b-481d7c18014f",
                "text": "lcy测试",
                "nodes": [
                    {
                        "id": "ad2af0c9-da6a-4ce6-a7be-a0bda2b0cd05",
                        "text": "1",
                        "nodes": [
                            {
                                "sysID": "04db531e-39c7-4fee-bf2b-13cbec867a5c",
                                "id": "04db531e-39c7-4fee-bf2b-13cbec867a5c",
                                "text": "测试",
                                "deviceNo": "123456789",
                                "sysTowerId": "ad2af0c9-da6a-4ce6-a7be-a0bda2b0cd05",
                                "TowerNo": "1",
                                "sysGridLineID": "6469f87b-0f96-454f-bf2c-09c0bca5dc07",
                                "LineName": "lcy测试",
                                "ChannelId": "123456789",
                                "NCWatermark": "220kV-lcy测试-1-大号侧---1",
                                "IsOnline": false,
                                "nodes": [
                                    {
                                        "id": "f85b1f47-a0ce-4c90-9b66-82243cb9edeb",
                                        "deviceid": "04db531e-39c7-4fee-bf2b-13cbec867a5c",
                                        "text": "1(1)",
                                        "chno": 1,
                                        "chid": ""
                                    },
                                    {
                                        "id": "fc4568e4-213a-4777-a54a-4a684d29ffc9",
                                        "deviceid": "04db531e-39c7-4fee-bf2b-13cbec867a5c",
                                        "text": "2(2)",
                                        "chno": 2,
                                        "chid": ""
                                    },
                                    {
                                        "id": "252c3eb2-5e59-4d94-98ab-b9840ea9a993",
                                        "deviceid": "04db531e-39c7-4fee-bf2b-13cbec867a5c",
                                        "text": "3(3)",
                                        "chno": 3,
                                        "chid": ""
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            {
                "id": "fcca1d11-ff1a-49b9-a7fa-143e65268de8",
                "voltageClass": "f1b055b9-d5cf-4f3f-a43b-481d7c18014f",
                "text": "ztz测试专线",
                "nodes": [
                    {
                        "id": "44063bc0-251a-4bc4-b696-7e60fead696d",
                        "text": "1",
                        "nodes": [
                            {
                                "sysID": "7aaf28ed-59d1-4b84-8abc-e7a874a4b581",
                                "id": "7aaf28ed-59d1-4b84-8abc-e7a874a4b581",
                                "text": "ztz测试专线-1",
                                "deviceNo": "ztz测试专线-1",
                                "channels": [
                                    {
                                        "id": "30a77965-6afc-43f7-b00a-e6fcf625a2c8",
                                        "deviceid": "7aaf28ed-59d1-4b84-8abc-e7a874a4b581",
                                        "text": "1(1)",
                                        "chno": 1,
                                        "chid": "34010000002000391"
                                    }
                                ],
                                "sysTowerId": "44063bc0-251a-4bc4-b696-7e60fead696d",
                                "TowerNo": "1",
                                "sysGridLineID": "fcca1d11-ff1a-49b9-a7fa-143e65268de8",
                                "LineName": "ztz测试专线",
                                "ChannelId": "34010000002000391",
                                "NCWatermark": "220kV-ztz测试专线-1-大号侧--1(1)-1",
                                "IsOnline": false
                            }
                        ]
                    },
                    {
                        "id": "cd8101f5-cab9-4c8b-a283-25e68ad45b1e",
                        "text": "2",
                        "nodes": [
                            {
                                "sysID": "10c07703-426b-4e11-b698-e3f89ad80368",
                                "id": "10c07703-426b-4e11-b698-e3f89ad80368",
                                "text": "34010000002000392",
                                "deviceNo": "34010000002000392",
                                "channels": [
                                    {
                                        "id": "cd8fcb66-af23-4830-a8e1-967c28beaa2c",
                                        "deviceid": "10c07703-426b-4e11-b698-e3f89ad80368",
                                        "text": "1(1)",
                                        "chno": 1,
                                        "chid": "34010000002000392"
                                    }
                                ],
                                "sysTowerId": "cd8101f5-cab9-4c8b-a283-25e68ad45b1e",
                                "TowerNo": "2",
                                "sysGridLineID": "fcca1d11-ff1a-49b9-a7fa-143e65268de8",
                                "LineName": "ztz测试专线",
                                "ChannelId": "34010000002000392",
                                "NCWatermark": "220kV-ztz测试专线-2-大号侧--1(1)-1",
                                "IsOnline": false
                            }
                        ]
                    },
                    {
                        "id": "7993f2f4-3f00-42fd-90c8-29ffb57ad6e3",
                        "text": "3",
                        "nodes": [
                            {
                                "sysID": "5fde5727-d75b-42ca-b2ba-a15a04d3f36c",
                                "id": "5fde5727-d75b-42ca-b2ba-a15a04d3f36c",
                                "text": "220kVztz测试专线 #3大号侧",
                                "deviceNo": "2024012900002",
                                "channels": [],
                                "sysTowerId": "7993f2f4-3f00-42fd-90c8-29ffb57ad6e3",
                                "TowerNo": "3",
                                "sysGridLineID": "fcca1d11-ff1a-49b9-a7fa-143e65268de8",
                                "LineName": "ztz测试专线",
                                "ChannelId": "2024012900002",
                                "NCWatermark": "220kV-ztz测试专线-3-大号侧---1",
                                "IsOnline": false
                            }
                        ]
                    }
                ]
            },
            {
                "id": "95e94977-86ae-4252-8d40-75a2feb33c92",
                "voltageClass": "f1b055b9-d5cf-4f3f-a43b-481d7c18014f",
                "text": "从化科技线路",
                "nodes": [
                    {
                        "id": "2b7b9b15-887e-434e-9665-cf74581b7510",
                        "text": "2",
                        "nodes": [
                            {
                                "sysID": "e1442e16-ed8a-4d4d-96ad-087915db9b7a",
                                "id": "e1442e16-ed8a-4d4d-96ad-087915db9b7a",
                                "text": "34010000002000391",
                                "deviceNo": "34010000002000391",
                                "channels": [
                                    {
                                        "id": "9f30cffb-e815-4e59-8c28-11f755a43898",
                                        "deviceid": "e1442e16-ed8a-4d4d-96ad-087915db9b7a",
                                        "text": "1(1)",
                                        "chno": 1,
                                        "chid": "34010000002000391"
                                    }
                                ],
                                "sysTowerId": "2b7b9b15-887e-434e-9665-cf74581b7510",
                                "TowerNo": "2",
                                "sysGridLineID": "95e94977-86ae-4252-8d40-75a2feb33c92",
                                "LineName": "从化科技线路",
                                "ChannelId": "34010000002000391",
                                "NCWatermark": "220kV-从化科技线路-2-大号侧--1(1)-1",
                                "IsOnline": false
                            }
                        ]
                    }
                ]
            }
        ]
    },
    {
        "id": "0f106455-7f91-4252-9af3-d45c0b741c3a",
        "text": "110kV",
        "nodes": [
            {
                "id": "78d5b790-6acd-4308-b3b7-cc87da97ac96",
                "voltageClass": "0f106455-7f91-4252-9af3-d45c0b741c3a",
                "text": "江西富Ⅰ线",
                "nodes": [
                    {
                        "id": "792ac297-877d-45ac-95ae-be65a07a0645",
                        "text": "1",
                        "nodes": [
                            {
                                "sysID": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                "id": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                "text": "3401000000112005Z",
                                "deviceNo": "3401000000112005Z",
                                "sysTowerId": "792ac297-877d-45ac-95ae-be65a07a0645",
                                "TowerNo": "1",
                                "sysGridLineID": "78d5b790-6acd-4308-b3b7-cc87da97ac96",
                                "LineName": "江西富Ⅰ线",
                                "ChannelId": "1",
                                "NCWatermark": "110kV-江西富Ⅰ线-1-小号侧--1(1)-1",
                                "IsOnline": false,
                                "nodes": [
                                    {
                                        "id": "9cc4c04e-aaae-44b9-a818-d0be28dcafff",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "1(1)",
                                        "chno": 1,
                                        "chid": "1"
                                    },
                                    {
                                        "id": "45e1802e-b989-41b2-83b9-1d0dad7ce95f",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "2(2)",
                                        "chno": 2,
                                        "chid": "2"
                                    },
                                    {
                                        "id": "68368d44-e17a-44c8-aa53-63ccd4ab1b99",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "3(3)",
                                        "chno": 3,
                                        "chid": "3"
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": "be9fd33f-614b-4e2c-8014-c9fe625ec58a",
                        "text": "2",
                        "nodes": [
                            {
                                "sysID": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                "id": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                "text": "3402000000222005Z",
                                "deviceNo": "3401000000112005Z",
                                "sysTowerId": "be9fd33f-614b-4e2c-8014-c9fe625ec58a",
                                "TowerNo": "2",
                                "sysGridLineID": "78d5b790-6acd-4308-b3b7-cc87da97ac96",
                                "LineName": "江西富Ⅰ线",
                                "ChannelId": "1",
                                "NCWatermark": "110kV-江西富Ⅰ线-2-小号侧--1(1)-1",
                                "IsOnline": false,
                                "nodes": [
                                    {
                                        "id": "9cc4c04e-aaae-44b9-a818-d0be28dcafff",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "1(1)",
                                        "chno": 1,
                                        "chid": "1"
                                    },
                                    {
                                        "id": "45e1802e-b989-41b2-83b9-1d0dad7ce95f",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "2(2)",
                                        "chno": 2,
                                        "chid": "2"
                                    },
                                    {
                                        "id": "68368d44-e17a-44c8-aa53-63ccd4ab1b99",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "3(3)",
                                        "chno": 3,
                                        "chid": "3"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            {
                "id": "833cd9e5-2f68-481c-80f8-2b9488caae87",
                "voltageClass": "0f106455-7f91-4252-9af3-d45c0b741c3a",
                "text": "江西富Ⅱ线",
                "nodes": [
                    {
                        "id": "0819da3e-1102-45d2-b409-c6bdb3eb0c5b",
                        "text": "1",
                        "nodes": [
                            {
                                "sysID": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                "id": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                "text": "3401000000112005Z",
                                "deviceNo": "3401000000112005Z",
                                "sysTowerId": "0819da3e-1102-45d2-b409-c6bdb3eb0c5b",
                                "TowerNo": "1",
                                "sysGridLineID": "833cd9e5-2f68-481c-80f8-2b9488caae87",
                                "LineName": "江西富Ⅱ线",
                                "ChannelId": "1",
                                "NCWatermark": "110kV-江西富Ⅱ线-1-小号侧--1(1)-1",
                                "IsOnline": false,
                                "nodes": [
                                    {
                                        "id": "9cc4c04e-aaae-44b9-a818-d0be28dcafff",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "1(1)",
                                        "chno": 1,
                                        "chid": "1"
                                    },
                                    {
                                        "id": "45e1802e-b989-41b2-83b9-1d0dad7ce95f",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "2(2)",
                                        "chno": 2,
                                        "chid": "2"
                                    },
                                    {
                                        "id": "68368d44-e17a-44c8-aa53-63ccd4ab1b99",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "3(3)",
                                        "chno": 3,
                                        "chid": "3"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    },
    {
        "id": "a6c63fc9-1ffc-48d1-8c7e-91def82ba0c5",
        "text": "10kV",
        "nodes": [
            {
                "id": "8b6a9183-9ed5-4545-b779-a54bc14992b9",
                "voltageClass": "a6c63fc9-1ffc-48d1-8c7e-91def82ba0c5",
                "text": "B710-hyl",
                "nodes": [
                    {
                        "id": "883fd287-329a-4497-8c3d-3f092509c52c",
                        "text": "1",
                        "nodes": [
                            {
                                "sysID": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                "id": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                "text": "3401000000112005Z",
                                "deviceNo": "3401000000112005Z",
                                "sysTowerId": "883fd287-329a-4497-8c3d-3f092509c52c",
                                "TowerNo": "1",
                                "sysGridLineID": "8b6a9183-9ed5-4545-b779-a54bc14992b9",
                                "LineName": "B710-hyl",
                                "ChannelId": "1",
                                "NCWatermark": "10kV-B710-hyl-1-小号侧--1(1)-1",
                                "IsOnline": false,
                                "nodes": [
                                    {
                                        "id": "9cc4c04e-aaae-44b9-a818-d0be28dcafff",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "1(1)",
                                        "chno": 1,
                                        "chid": "1"
                                    },
                                    {
                                        "id": "45e1802e-b989-41b2-83b9-1d0dad7ce95f",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "2(2)",
                                        "chno": 2,
                                        "chid": "2"
                                    },
                                    {
                                        "id": "68368d44-e17a-44c8-aa53-63ccd4ab1b99",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "3(3)",
                                        "chno": 3,
                                        "chid": "3"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            {
                "id": "2529c673-d824-472c-ba78-a10768d26b86",
                "voltageClass": "a6c63fc9-1ffc-48d1-8c7e-91def82ba0c5",
                "text": "B710-支线一",
                "nodes": [
                    {
                        "id": "a86c6694-1642-43e1-8110-d845506f32d5",
                        "text": "36",
                        "nodes": [
                            {
                                "sysID": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                "id": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                "text": "3403600000036362005Z",
                                "deviceNo": "3401000000112005Z",
                                "sysTowerId": "a86c6694-1642-43e1-8110-d845506f32d5",
                                "TowerNo": "36",
                                "sysGridLineID": "2529c673-d824-472c-ba78-a10768d26b86",
                                "LineName": "B710-支线一",
                                "ChannelId": "1",
                                "NCWatermark": "10kV-B710-支线一-36-小号侧--1(1)-1",
                                "IsOnline": false,
                                "nodes": [
                                    {
                                        "id": "9cc4c04e-aaae-44b9-a818-d0be28dcafff",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "1(1)",
                                        "chno": 1,
                                        "chid": "1"
                                    },
                                    {
                                        "id": "45e1802e-b989-41b2-83b9-1d0dad7ce95f",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "2(2)",
                                        "chno": 2,
                                        "chid": "2"
                                    },
                                    {
                                        "id": "68368d44-e17a-44c8-aa53-63ccd4ab1b99",
                                        "deviceid": "6d5d824f-ad5d-40ca-bfe3-b173b77e3a0a",
                                        "text": "3(3)",
                                        "chno": 3,
                                        "chid": "3"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    }
]
function getLastLevelItems(arr) {
    let lastLevelItems = [];

    function getLastLevel(nodes) {
        nodes.forEach(node => {
            if (Array.isArray(node.nodes) && node.nodes.length > 0) {
                getLastLevel(node.nodes);
            } else {
                if (node.deviceNo || node.chno) { }
                lastLevelItems.push(node);
            }
        });
    }

    getLastLevel(arr);
    return lastLevelItems;
}
const lastLevelItems = getLastLevelItems(data);
console.log(lastLevelItems);
console 命令行工具 X clear

                    
>
console