字串的方法

2021-09-01 11:20:23 字數 871 閱讀 5913

1. charat(下標)作用:查詢該下標位置處的字元,返回乙個字元

2. charcodeat(下標)作用:查詢該下標位置處的字元的unicode編碼

3. fromcharcode()作用:根據乙個unicode編碼值返回對應的字元,與charcodeat()結果相反

4. indexof()作用:查詢某個字元在字串中首次出現的位置

5. lastindexof()作用:查詢某個字元在字串中最後出現的位置

6. split("字元")作用:通過某個字元對字串進行分割,最終將字串轉成陣列

7. concat()作用:連線兩個字串

8. trim()作用:去掉字串兩端的空白字元

9. search()作用:查詢子串在父串的位置

10. replace(引數1,引數2)作用:將字串中的引數1替換成指定的引數2

11. tolowercase()作用:大寫轉小寫

12. touppercase()作用:小寫轉大寫

13. substr(起始下標,長度)作用:從起始位置擷取 指定長度的字串

14. substring(起始位置,結束位置)作用:從起始位置擷取到結束位置處的字元

15. codepointat()作用:取對應字元對應的編碼值

16. string.fromcodepoint()作用:返回編碼對應的字元,識別大於0xffff的字元

17. for...of 字串的遍歷器介面

18. includes()作用:判斷字串是否包含某些字元返回布林值

19. startwith(),endswith()作用:判斷乙個字串是否以某些字元開始或結束,返回布林值

20. repeat()作用:將原字串重複n次,返回新字串

字串及字串的方法

一 字串 js中的任何資料型別都可以當作物件來看。所以string既是基本資料型別,又是物件。二 宣告字串 var sstr 字串 var ostr new string 字串 三 字串屬性 1.length計算字串的長度 不區分中英文 var str hello world console.log...

字串的方法

獲取 int length 獲取長度 char charat int index 獲取位置上的某個字元 int indexof int ch 因為接受的是asc 碼,返回的是ch在字串中出現的第一次位置 int indexof int ch,int fromindex 從fromindex指定位置獲...

字串的方法

str hello atguigu str2 中hello atguigu console.log str.charat 0 根據索引獲取指定的字元 console.log str2.charcodeat 1 獲取索引處的字元編碼 unicode編碼 console.log string.fromc...