1.对象
- 简单类型:undefined null boolean number string
- 复杂类型:对象(object{}括起来)
2.object对象
- 对象定义
var student = { name:'Tom', age=21}
- 对象属性获取
name = student.name
name = student['name']
3.输出
- 控制台输出console.log()
- 对话框输入:a = prompt(1+2=?)?
对话框输入的结果即为a的值
4.Hash数组
- Hash数组定义
var stu_score = {'杨璐':131,
'王雪':131,
'韩林霖':127,
'沙龙逸':123,
'李鉴学':126,
'韩雨萌':129,
'刘帅':116,
'康惠雯':114,
'刘钰婷':115};
- 添加数组元素
stu_score['林世博'] = 116
- 遍历Hash数组
var all_scores = {'杨璐':131,
'王雪':131,
'韩林霖':127,
'沙龙逸':123,
'李鉴学':126,
'韩雨萌':129,
'刘帅':116,
'康惠雯':114,
'刘钰婷':115,
'林世博':116};
var stu_names = ['杨璐','王雪','韩林霖','沙龙逸','李鉴学','韩雨萌','刘帅','康惠雯','刘钰婷','林世博'];
//打印所有的学生的成绩(只打印成绩。)
for(var i in stu_names)
console.log(all_scores[stu_names[i]])
5.增强for循环(i为数组下标)
//变量scores存储的是某学生语文、数学、英语三科的成绩
var scores = [131,142,144];
//使用for循环统计各科成绩,并求平均分
var sum_scores = 0;
//添加for循环语句
for(var i in scores){
// console.log(score)
sum_scores += scores[i]
}
//求三科的平均分数
var average_score = sum_scores / scores.length;
console.log('三科的平均成绩为:'+average_score);