数组与遍历
数组:把多个值按顺序放在一起
先认识数组,再学习 for...of。数组从索引 0 开始计数,length 表示元素数量。
- [] 创建数组;students[0] 读取第一个元素。
- push 添加到末尾,会修改原数组。
- 越界读取通常得到 undefined,不会自动得到最后一项。
- 口头预测:添加后 length 是多少?students[1] 是谁?
const students = ["小林", "小周"];
students.push("小吴");
console.log(students.length); // 3
console.log(students[1]); // 小周