數(shù)組對(duì)象方法:
Array.isArray(val);??檢測(cè)是不是數(shù)組??返回true就是數(shù)組,flase就不是數(shù)組
arr.forEach(function(ele,index,array){});//本質(zhì)上是一個(gè)for循環(huán)(遍歷數(shù)組的元素/下標(biāo)/數(shù)組,三個(gè)值)
arr.indexOf(ele);//檢測(cè)ele在數(shù)組arr中是否存在?(存在返回所在下標(biāo),不存在返回-1)(都可以傳負(fù)數(shù))
arr.lastIndexOf(ele);//從后往前找
var?flag?=?arr.some逐個(gè)執(zhí)行,只要有一個(gè)為true,整個(gè)結(jié)果就為true
arr.every(function?(ele)逐個(gè)執(zhí)行,只要有一個(gè)為false,整個(gè)結(jié)果就為false
arr.filter(function(ele,index,array){//過濾,返回布爾值,返回一個(gè)新的數(shù)組
arr.map(function(ele,index,array){//映射,返回一個(gè)新的數(shù)組
reslut?=?arr.reduce(function(prev,next){?執(zhí)行結(jié)果歸并為一個(gè)值/對(duì)象/數(shù)組
String字符串對(duì)象方法:
var?str1?=?new?String("jk&fal&sj");???//?字符串對(duì)象構(gòu)造方式????少用
var?str2?=?"jk&fal&sj"??????????//字符串字面量構(gòu)造方式?????常用
alert(str1?==?str2)//str1?==?str2???但是?str1?!===?str2
console.log(str2.charAt(5))???????//輸出index下標(biāo)對(duì)應(yīng)的字符。沒有返回空
alert(str2.charCodeAt(5))????????????//輸出index下標(biāo)對(duì)應(yīng)字符的ASCLL碼值???沒有返回NAN
alert(String.fromCharCode("A"))?????????????//輸人ASCLL碼值輸出字符
console.log(str1.indexOf("j"));?
console.log(str1.indexOf("j",2));????????//查詢ele在字符串中是否存在,存在返回下標(biāo),不存在返回-1;
console.log(str1.lastIndexOf("s"))???????????//從后往前找;
console.log(str1.substr(0,4));?//length可省略,截取從start位置到指定長度的字符,如果長度不指定,截取到最后
console.log(str1.substr(3));
console.log(str1.substring(0));??????????????//end可省略,截取從start位置到end位置的字符,但不包括end,如果end不指定,截取到最后
console.log(str2.split("&"));???????????????//將字符轉(zhuǎn)成數(shù)組
console.log(str2.replace("j","k"));????????//返回替換后的新字符串,默認(rèn)情況下只能替換一個(gè),如果需要替換多個(gè),需要使用正則
console.log(str2.toLowerCase());???????????//將字母大寫改為小寫,原字母小,就不變console.log(str2.toUpperCase(0));???????????//將字母小寫改為大寫,原字母小,就不變
Math對(duì)象方法:
Math.floor()向下取整
Math.ceil()向上取整
Math.round()四舍五入
Math.sqrt(m)開平方
Math.pow(m,?n)?m的n次方
Math.min(342,?32,?2)?2
Math.min.apply(null,?[34,?1,?35])?1?獲取數(shù)組的最小值
Math.random()[0,?1)?之間的隨機(jī)小數(shù)
Date對(duì)象方法:
console.log(date.getFullYear())?//獲取年
console.log(date.getMonth()?+?1)//?獲取月份(月份從0?-?11,所以獲取時(shí)?月份要?+?1)
console.log(date.getDate())//?獲取日期
console.log(date.getDay())//?獲取星期?0?-?6?0?==?星期日
console.log(date.getHours())//?獲取小時(shí)
console.log(date.getMinutes())//?獲取分鐘
console.log(date.getSeconds())//?獲取秒
console.log(date.toLocaleDateString())???//精確到日期
console.log(date.toLocaleString())??獲得本地時(shí)間? 精確到小時(shí)
返回毫秒數(shù)的三種方法:
console.log(date.getTime())
console.log(Date.now())
console.log(Date.parse(date))
定時(shí)器:
setInterval(要執(zhí)行的任務(wù),間隔時(shí)間)
clearInterval(t);停止t定時(shí)器
setTimeout (要執(zhí)行的任務(wù),延遲時(shí)間)? ?