個人習慣用思維導圖做筆記,重新敲一遍加深印象
js內置對象
Object Array Function Math Date String Number Boolean RegExp(正則表達式)
對象API
String屬性
String方法
|
|
|
str.charAt() |
獲取字符串某一個下標字符 |
|
str.concat() |
拼接字符串 |
|
str.indexOf() |
判斷字符串是否包含某個字符串。(返回第一次出現的位置) |
|
str.lastIndexOf() |
獲取某字符最後一次出現的位置 |
|
str.substr() |
截取字符串 |
|
str.replace(‘a’,‘b’) |
修改字符串 |
默認替換第一個匹配的字符,請使用正則表達式全局匹配 |
str.search() |
返回第一次和正則表達式匹配的索引,無結果時返回-1 |
|
str.march() |
提取字符串中與正則表達式匹配的文本,返回數組 |
|
str.toLowerCase() |
轉小寫 |
|
str.toUpperCase() |
轉大寫 |
|
str.split() |
分隔字符串 |
|
str.trim() |
去除字符串兩端的空格 |
|
Array屬性
Array方法
|
|
|
arr.concat() |
連接數組 |
|
arr.join() |
將數組元素拼接成字符串 |
|
arr.pop() |
刪除數組最後一個元素 |
|
arr.push() |
往數組後面添加一個元素 |
|
arr.reverse() |
翻轉數組 |
|
arr.shift() |
刪除數組第一個元素 |
|
arr.slice() |
選取數組指定區間的元素 |
|
arr.soft() |
根據函數條件對數組排序 |
soft(function(){retrun a-b})//升序 |
arr.indexof() |
返回指定字符串第一次出現位置的下標 |
|
arr.filter() |
根據一個函數條件返回新數組,不會改變原數組 |
filter(function(a){return a<10}) |
Number方法
|
|
toString() |
轉爲字符串 |
toFixed() |
返回指定位數的小數 |
Math屬性
|
|
Math.E |
常數e。 |
Math.PI |
常數Pi。 |
Math方法
|
|
Math.abs() |
返回絕對值 |
Math.ceil() |
向上取整 |
Math.floor() |
向下取整 |
Math.max(n1,n2,…) |
返回最大值 |
Math.min(n1,n2,…) |
返回最小值 |
Math.pow(n,e) |
指數運算 |
Math.sqrt() |
返回參數值的平方根 |
Math.log() |
返回以e爲底的自然對數值 |
Math.exp() |
e的指數 |
Math.round() |
四捨五入 |
Math.random() |
返回0~1的隨機數。[0,1) |
console方法
|
|
console.log(text,text2,…) |
在console窗口輸出信息 |
console.info() |
console窗口輸出信息,內容一般是正式的 |
console.debug() |
在console窗口輸出信息 |
console.warn() |
輸出信息,表示警告 |
console.error() |
輸出信息,表示出錯 |
console.table() |
將複合類型的數據轉爲表格顯示 |
console.count() |
計數,輸出被調用次數。 |
console.dir() |
可打印object對象 |
console.dirxml() |
顯示DOM節點 |
console.time() |
計時開始 |
console.timeEnd() |
計時結束 |
console.profile() |
新建一個性能測試器 |
console.profileEnd() |
結束正在運行的性能測試器 |
console.clear() |
清除控制檯的所有輸出 |
Object方法
|
|
Obj.getOwnPropertyName() |
遍歷對象不可枚舉的屬性 |
Function屬性
|
|
caller |
獲取調用當前函數的引用(誰調用的函數) |
length |
獲取函數形參個數 |
name |
獲取函數名 |
arguments |
獲取所有實參(arguments屬性區分arguments關鍵字) |
Function方法
|
|
apply() |
修改this指向 |
call() |
修改this指向 |
valueOf() |
返回函數對象自身 |
toString() |
返回定義該Function對象的字符串 |
bind() |
修改this指向 |
數據類型轉換
parseInt();轉整型,從左往右解析,遇到非數字結束
parseFloat();轉浮點型,從左往右解析,識別第一個小數點
Number(變量);將變量轉數字
toString();將對象轉字符
String(變量);將變量轉字符,變量爲undefined、null時不會報錯
Boolean(變量);將變量轉布爾值
!!();將變量轉布爾值
Document對象屬性
|
|
document.body |
|
document.documentURI |
當前文檔的網址 |
document.domain |
返回文檔域名 |
document.lastModified |
返回文檔最後修改時間戳 |
document.location |
返回location對象,提供文檔URL信息 |
document.referrer |
返回文檔訪問來源 |
document.title |
返回文檔標題 |
document.characterSet |
返回渲染當前文檔的字符集 |
document.readyState |
返回當前文檔的狀態 |
document.designMode |
控制當前文檔是否可編輯,可讀寫 |
document.compatMode |
返回瀏覽器處理文檔的模式 |
document.cookie |
用來操作Cookie |
document.links |
返回當前文檔的所有a元素 |
document.forms |
返回頁面中所有表單元素 |
document.images |
返回頁面中所有圖片元素 |
document.embeds |
返回網頁中所有嵌入對象 |
document.scripts |
返回當前文檔的所有腳本 |
document.styleSheets |
返回當前網頁的所有樣式表 |
document.doctype |
返回與文檔相關的文檔類型聲明 |
document.documentElement |
返回當前文檔的根節點 |
document.defaultView |
返回document對象所在的window對象 |
document.head |
返回head元素 |
document.activeElement |
返回當前文檔中獲得焦點的那個元素 |
不定期更新…