totalsum.push(sum2, this.state.totalsum) for (let i = 0; i < totalsum.length; i++) { sum += totalsum[i] }
时间: 2024-05-12 07:19:49 浏览: 16
This code snippet has a few issues that need to be resolved.
First, the `push` method is being called with two arguments, `sum2` and `this.state.totalsum`. This will add both values as separate elements to the end of the `totalsum` array. If you want to concatenate these arrays, you can use the spread operator like this:
```
totalsum.push(...sum2, ...this.state.totalsum);
```
Second, the `for` loop has a condition that will result in an infinite loop. The loop variable `i` is never incremented or decremented, so it will always be equal to zero and the loop will never terminate. To fix this, you can add `i++` to the end of the loop body:
```
for (let i = 0; i < totalsum.length; i++) {
sum = totalsum[i];
// more code here
}
```
Finally, it's not clear what you want to do with the `sum` variable inside the loop. As it's currently written, it will just overwrite its value on each iteration, so you'll end up with the last value in the array. If you want to do something with each element of the array, you'll need to add more code inside the loop.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)