1、查詢是否包含贏一個字符串
'xxxx'.includes(x,i);//x子字符串,i起始位置
2、forEach(數(shù)組的循環(huán)不能中斷)
array.forEach(function(currentValue,index,array){})
//必須 currentValue: 當(dāng)前的元素
//可選 index:當(dāng)前元素的索引值
//可選 array: 當(dāng)前元素所屬的數(shù)組對象
3、創(chuàng)建類
class Human {
constructor(name) {
this.name = name;
}
breathe() {
console.log(this.name + " is breathing");
}
}
var human = new Human("yancy");
human.breathe();//yancy is breathing
//繼承
class Man extends Human {
constructor(name,sex){
super(name);//es6語法 訪問父級對象上的構(gòu)造函數(shù)
this.sex = sex;
}
info(){
console.log(`${this.name} is ${this.sex}`);
}
}
var man = new Man('henry','boy');
man.breathe();//henry is breathing
man.info();//henry is boy
4、箭頭函數(shù)
var arr = ['A', '', 'B', null, undefined, 'C', ' '];//刪掉空字符串
var newArr = arr.filter( val => (val && val.trim()));//newArr = ['A','B','C']