【发布时间】:2021-05-21 02:40:16
【问题描述】:
我有一个数组,我想用 for 循环一个一个地渲染这个数组。 我不知道如何获得数组的长度,知道吗? 感谢您的帮助。 这是我的代码:
this.state = {
array: []
}
// here is the function to write data into array
render(){
return(
<div>
for(let i = 0; i < this.state.array.length; i++) { //this line doesn't work, error with length part
<p> {this.state.array[i]}</p> // this line will work if I wirte outside of loop
}
</div>
)
}
【问题讨论】:
标签: reactjs for-loop state render