慕的地6264312
用这个function getChildOf(x){ var keys = x.split("*") let tempObj = obj; for (const key of keys) { tempObj = tempObj[key] } return tempObj;}// Test with your datavar obj={ "Total Cost of Ownership": { "Operational Cost": { "Asset Cost": { "Maintenance": { "Scheduled": { "Predictive": [ "Parts", "Labours", "Consumables" ], "Periodic": [ "Parts", "Labours", "Consumables" ] }, "Unscheduled": [ "Parts", "Labours", "Consumables" ], "Other Maintenance": [ "Parts", "Labours", "Consumables" ] }, "Compliance": [ "Emissions", "HOS" ] }, "Under Utilization Cost": [ "Asset Unassigned", "LTL", "Empty Miles", "Downtime", "Idling Time", "Crew Unassigned Time" ], "Route Cost": { "Fuel": [ "Defined Route", "Excess Miles", "Unattributable Miles" ], "Charging": { }, "Wait Time": { }, "Toll": { } }, "Crew Cost": [ "Driving Violations", "Slary & Insurance", "Training" ], "Unsafe Operations Cost": [ "Fatalities", "Injuries", "Unsalvageable Vehicles" ] } }}var str1 = "Total Cost of Ownership";var str2 = "Total Cost of Ownership*Operational Cost*Asset Cost";console.log(getChildOf(str1));console.log(getChildOf(str2));