//请教如何简化如下代码:
Txt = {content0: "", content1: "", content2: "", content3: "", content4: "", content5: "", content6: "", content7: "", content8: "", content9: "", content10: "", content11: "", content12: "", content13: "", content14: "", content15: "", content16: "", content17: "", content18: "", content19: "", content20: ""}
let Txt={}, a = new Array(21).fill('')
a.forEach((v,i)=>{Txt['content'+i]=v})
写写看,没验证。可读性还不如原文。
谢啦!调试如下:
let a = new Array(21).fill("")
a.forEach((v, i) => { Txt[`content${i}`] = v })
for(let i=0;i<21;i++) Txt[`content${i}`] =""
感谢,又省一行。