1. 常用及特殊
1. 字符串模板
2. 箭头函数
3. 变量
let 与 var ,let定义在 for{ let name = "jay"; } 外面取不到,var 可以取得
const 不可变
4. 展开
function hello( name1, name2){
console.log(name1, name2)
}
const arr = ['imooc' , 'woniu' ];
1.) hello.apply(null,arr); // imooc woniu
2.) hello(...arr); // imooc woniu
5. 对象扩展
const obj = {name:'imooc', course:' react'};
1.) Object.keys()
console.log(Object.keys(obj)); // ['name', 'course']
2.) Object.values()
console.log(Object.values((obj)); // ['imooc' , 'react' ]
3.) Object.entries()
console.log(Object.entries(obj)); //[ ['name', 'course'] , ['imooc' , 'react' ] ]
4.)
const name = 'imooc';
const obj = {
name:'hello'
}
const obj1 = {
[name]:'hello'
}
console.log(obj); // { name:'hello' }
console.log(obj1); // { imooc:'hello' }
5.) 合并
const obj = { name:'imooc', course:'react' };
const obj2 = {type:'IT', name:'woniu'};
console.log({...obj, ...obj2}); // { name:'woniu', course:'react', type:'IT'}
//同等于:
console.log(Object.assign({}, obj, obj2)); // {name:'woniu', course:'react', type:'it'}
console.log({...obj, ...obj2,date:'110'}); // {name:'woniu', course:'react', type:'IT', date:'110'}
6.) 结构赋值
const obj = { name:'imooc', course:'react' };
const { name, course } = obj;
console.log( name, course ); // imooc react
6. 数组
0.)解构
let a = 3, b=6;
[a , b] = [b , a];
1.) 合并
const arr2 = [1,2];
const arr3 = [3,4];
console.log([...arr2, ...arr3]); // [1,2,3,4]
2.) 结构赋值
const arr = ['hello', 'imooc'];
常规: let arg1 = arr[0];
let arg2 = arr[1];
现在: let [ arg1, arg2 ] = arr;
console.log( arg1, arg2 ); // hello imooc
7. class 语法糖
之前使用面向对象,定义函数定义它的propetype;
现在class;
1.)
class MaApp{
constructor() {
this.name = 'imooc'
}
sayHello(){
console.log(`hello ${this.name} !`)
}
}
const app = new MyApp();
app.sayHello(); // hello imooc !
=====
8. 代码片段
1.)所以数组是否通过测试
[1,2,3,4,5].every( v => v>3); //false
2.)是否有元素通过测试
[2,3,4,5].some(v=>v>3); //true
3.)过滤数组
[1,2,3,4,5].filter(v=>v>3); // 4,5
4.)去重
const arr = [1,2,3,4,3,2];
[...new Set(arr)]; // [1,2,3,4]
5.)获取对象的key
const obj = {name:'WR',age:1};
Object.keys({obj}); // [name,age]
6.)获取对象里数据的数量
Object.keys({name:'1', age:'11'}.length);
7.)