1 const json = { 2 a: { b: { c:1 } }, 3 d: { e: 2 }, 4 }; 5 6 const path = [‘d‘,‘e‘]; 7 8 let p = json; 9 path.forEach(k => { 10 p = p[k]; 11 }); 12 console.log(p);
2021-10-28 06:00:09
1 const json = { 2 a: { b: { c:1 } }, 3 d: { e: 2 }, 4 }; 5 6 const path = [‘d‘,‘e‘]; 7 8 let p = json; 9 path.forEach(k => { 10 p = p[k]; 11 }); 12 console.log(p);
下一篇:JS集合Set