目錄
2.實時刷新
1.項目初始化
npm init
2.安裝
cnpm i -g live-server
3.啓動
live-server
3.查找字符串
indexOf()
let blog = `向暖lalallzenm hdjhd糖糖shd`
document.write(blog.indexOf('糖糖')==-1)//false
includes()
let blog = `向暖lalallzenm hdjhd糖糖shd`
document.write(blog.includes('糖糖'))//true
startsWith()
let blog = `向暖lalallzenm hdjhd糖糖`
document.write(blog.startsWith('糖糖'))//false
endsWith()
let blog = `向暖lalallzenm hdjhd糖糖`
document.write(blog.endsWith('糖糖'))//true
4.複製字符串
let blog = `糖糖`
document.write(blog.repeat(10))
5.數字的操作
//二進制聲明 Binary
let binary = 0B010101;
document.write(binary)//21
//八進制聲明 Octal
let octal = 0o666;
document.write(octal)//438
//判斷是否是數字
let a =20 ;
document.write(Number.isFinite(a))//true
document.write(Number.isFinite(NaN))//false
document.write(Number.isFinite(undefined))//false
//isNaN 和 Number.isNaN
//isNaN:只是判斷傳入的參數是否能轉換成數字,並不是嚴格的判斷是否等於NaN,如果成功返回false,如果失敗返回true
document.write(isNaN('true'))//true
//判斷傳入的參數是否嚴格的等於NaN(也就是 ===),不存在類型轉換的行爲
document.write(Number.isNaN(1))//fasle
document.write(Number.isNaN(1/'測試'))//true
//判斷是否爲整數
let a = 999.1;
document.write(Number.isInteger(a))//false
6.數組
//json的數組格式
let json = {
"0":"糖糖",
"1":18,
"2":"女",
length:3
}
let arr = Array.from(json);
console.log(arr);//["糖糖", 18, "女"]
let arr2 = Array.of(2,3,5);
console.log(arr2);//[2,3,5]
//find()實例方法
//value:當前查找的值
//index:索引
//arr:原型
let arr = [2,3,4,5,6,7];
console.log(arr.find(function(value,index,arr){
return value > 5//查找第一個並返回
}))
for ... of
let arr =['age','vivi','bibi','yoyo',18];
for(let item of arr.entries()){
console.log(item)
}
function add(a,b=1){
if(a==0){
throw new Error('A is Error')
}
return a+b
}
console.log(add.length)//1 只顯示必須傳遞的
//Es6
var add=(a,b=1)=>a+b;
console.log(add(2));//3