let Array: any = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
我怎麼可以轉換這個數組爲對象象下面這樣:創建基於陣列的JavaScript對象
let Object: any = {
time: {
headerName: ""
},
monday: {
headerName: "Monday"
},
tuesday: {
headerName: "Tuesday"
},
wednesday: {
headerName: "Wednesday"
},
thursday: {
headerName: "Thursday"
},
friday: {
headerName: "Friday"
},
saturday: {
headerName: "Saturday"
},
sunday: {
headerName: "Sunday"
}
};
任何想法的傢伙?對不起,剛接觸JavaScript的人很安靜。我怎麼寫一個for循環,以便我可以實現這個結果?在此先感謝球員
你嘗試過什麼嗎? –
是的,試着循環遍歷數組。但我卡在對象部分 – blackdaemon
不知道如何繼續。是否我用我期望的數據結構聲明對象 – blackdaemon