3.3 对象
创建对象 若干个键值对
let 对象名 = {
属性名:属性值,
属性名:属性值,
属性名:属性值
}
注意:最后一行代码不需要逗号
JS中的对象 {…} 表示一个对象, 键值对描述属性 xxxx : xxxx
1
对象赋值 直接使用“=”赋值
2使用一个不存在的对象属性,不会报错 undefined
3动态的删减属性,通过delete删除对象的属性
delete person.name
true
person
4,动态的添加,直接给新的属性添加值即可
5,判断这个属性值是否在对象之中
‘age’ in person
true
6,判断这个属性是否是自身拥有的 hasOwnProperty()
person.hasownPreperty(’‘age’)
3.4 流程控制
1,if else
<script>
let a = 12;
if(a>11){
alert("fff");
}else{
alert("aas");
}
</script>
2,for循环 while循环
3.5 Map和Set
"use strict"
//Map
//学生的成绩,学生的名字
// var names=
// var scores=
let map = new Map([['tom',100],['jack',80],['haha',500]]);
let name = map.get('tom');//通过key获得values
console.log(name);
map.set(‘afdff’,123456);//往里边插入数据
Set :无序不重复的集合
let set = new Set([1,5,74,4,4]);//可以去重
set.add 插入一个元素
delect方法,删除一个元素
console.log(set.has())//是否包含某个元素
3.6 iterator //ES6新特性
for in 打印下标
for of 打印值
<script>
let arr = [4,6,5];
for(let x in arr){
console.log(x);
}
for(let x of arr){
console.log(x);
}
</script>
遍历数组
遍历Map
let map = new Map([["tom",110],["fff",100],["ada",500]]);
for(let x of map){
console.log(x);
}
遍历set
let map = new Map([["tom",110],["fff",100],["ada",500]]);
for(let x of map){
console.log(x);
}