数组
let cars = [“Saab”, “Volvo”, “BMW”];
数组的索引是从0开始
数组长度为lenth
数组最后一位cars[lenth-1]
对象
let car = {type:”porsche”, model:”911”, color:”white”};
js中对象的属性就是键值对
访问对象的属性位car.type
解构
1.数组解构
let[a,b,c]=[1,2,3];
let[a…c]=[1,2,3,4,5];
let[,,a,,]=[1,2,3,4,5]; a=5
2.对象解构
({ID,name})={ID:10,name:”电脑”}
3.参数解构
let sum=([a,b])=>a+b;
sum[30,50]等价于sum(30,50)
对象访问器
1.get作用是获取
let person = {
firstName: “Bill”,
lastName : “Gates”,
language : “en”,
get lang() {
return this.language;
}
};
2.set是写入
let person = {
firstName: “Bill”,
lastName : “Gates”,
language : “”,
set lang(lang) {
this.language = lang;
}
};