写js第一次错误
在写for (let i = 0; i <=names.length ; i++) {
names[i] = names[i] + '老师‘
}
console.log(names)
中时 i <=names.length 多写了一个等于号 就出现错误
![](https://i-blog.csdnimg.cn/blog_migrate/5d2df2ea250d45a823bf1d2306fe1b01.png)
数组是从0到数组中的个数(n)减1 多了个等于号 for运算时 多了运算 内存多了
解决:
去掉等于号
![](https://i-blog.csdnimg.cn/blog_migrate/a4b378ac70187efdffc3ed5e836ad0ab.png)
结果
![](https://i-blog.csdnimg.cn/blog_migrate/36d1f977474b12027db1a78a55593f7d.png)
在names.lehgth后面添加-1
![](https://i-blog.csdnimg.cn/blog_migrate/e49102f267a50ae69a43e3e5619199dc.png)
结果
![](https://i-blog.csdnimg.cn/blog_migrate/c1fd448506136283f22369001fe9e661.png)
写js第一次错误
在写for (let i = 0; i <=names.length ; i++) {
names[i] = names[i] + '老师‘
}
console.log(names)
中时 i <=names.length 多写了一个等于号 就出现错误
数组是从0到数组中的个数(n)减1 多了个等于号 for运算时 多了运算 内存多了
解决:
去掉等于号
结果
在names.lehgth后面添加-1
结果