封装个函数,把年份传进去就行了 const months = []; for (let i = 1; i <= 12; i++) { const month = { value: `${i}`, label: `${i}月`, children: [], }; const daysInMonth = new Date(2023, i, 0).getDate(); for (let j = 1; j <= daysInMonth; j++) { month.children.push({ value: `${j}`, label: `${j}号`, }); } months.push(month); } console.log(months);