我是编程新手。我正在尝试 React 并具有函数 addComment,该函数在用户向新闻添加评论时执行。此时我需要创建一个属性评论(数组)并分配或推送到该数组的inputCommentValue值。但是现在我只重写了数组的 0 个元素,无法添加新元素。你能告诉我把push方法放在哪里吗?谢谢!
var ARTICLES = [{
title: "sit amet erat",
text: "nam dui proin leo odio porttitor id consequat in consequat ut nulla sed accumsan"
}, {
title: "pulvinar sed",
text: "velit id pretium iaculis diam erat fermentum justo nec condimentum"
}]
addComment(index, inputCommentValue){
ARTICLES = [...ARTICLES], ARTICLES[index].comments=[inputCommentValue];
this.setState({ARTICLES:ARTICLES});
}