- let , const
- 模块化 export import
sample:
//导出main.js
export let name = 'Dua';
export function dua(arg) {
return arg;
}
//导入
import {name, dua} from 'main'
- 结构数组和对象
数组:
const arr = [1,3,5,7]
//不想要的元素用空格代替
let[a,b] = arr
let [a,,c] = arr
对象
const obj = {
a:1,
b:2,
c:3,
d:4
}
let {a,b,c,d} = obj
//使用冒号修改获取的key值
let {a:k, b:e, c: f, d:g} = obj
技巧:
- 交换数组变量的值
let colors = ['green', 'red'];
let {green, red} = colors;
let newColors = [red, green];
- 删除某一个对象的属性
const obj = {
a:1,
b:2,
c:3,
d:4
}
需求: 删除对象中的a, d属性
//定义想要删除的属性,剩余的属性用...加变量名表示
let {a,d, ...other} = obj
//删除了a,d属性
let newObj = other
- 合并数组
let arr1 = [0,1,2];
let arr2 = [3,4,5];
let arr4 = [8,7,...arr2, 9]
- 将数组作为函数的参数解构传入
5. 克隆对象,合并对象
let obj1= {name: 'dua', age: 18};
let obj2 = {city: 'beijing'};
let obj4= {...obj1, ...obj2};
- 函数参数赋值默认值
5. async , await
6. includes 判断是否包含
7. 指数运算符
8. Object.keys, Object.values, Object.entries
entries代表的是所有的键值对数组,用于遍历非常方便
const obj = {a: 1, b: 2, c: 3};
Object.entries(obj); //[a,1],[b,2],[c,3];
for(let [key, value] of Object.entries(obj)) {
console.log(`key: ${key} value: ${value}`)
}