const json = { "胡加健": { "2023-04-17": [ "苏E3M566" ], "2023-04-18": [ "苏EUD312" ] }, "沈智彦": { "2023-04-07": [ "苏E3M566" ] }, "董雅顺": { "2023-04-07": [ "苏EUD312" ], "2023-04-10": [ "苏E3M566" ] }, "俞佳浩": { "2023-04-10": [ "苏EUD312" ], "2023-04-11": [ "苏E12513" ] }, "李鹏": { "2023-04-12": [ "苏E3M566" ], "2023-04-13": [ "苏E3M566" ], "2023-04-20": [ "苏EUD312" ] } };

const dates = Object.values(json) .flatMap((person) => Object.keys(person)) .filter((date, index, self) => self.indexOf(date) === index) // 去重 .sort();

console.log(dates); // ["2023-04-07", "2023-04-10", "2023-04-11", "2023-04-12", "2023-04-13", "2023-04-17", "2023-04-18", "2023-04-20"]

获取下面json中的所有日期并排序重复日期归一空置日期自动补充。json: 胡加健 2023-04-17 苏E3M566 2023-04-18 苏EUD31

原文地址: https://www.cveoy.top/t/topic/bQdM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录