<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## String 對象 String對象是JavaScript提供的原生數據類型的包裝對象,用來生成字符串的包裝對象。 String對象的方法也可以在基本的字符串值中訪問到。 ~~~javascript var s = "hello"; var ss = new String("hello"); console.log(typeof ss); // object console.log(String(true)); // true console.log(String(123)); // 123 ~~~ ## 1.String對象的屬性和方法 `length`屬性:返回字符串的長度 `charAt()`方法:返回指定位置的字符,參數從0開始編號 `concat()`方法:用于連接兩個字符串,返回一個新的字符串,不改變原字符串 `slice()`方法:用于從原字符串中取出子字符串,并返回,不改變原字符串 `substring()`方法:用于從原字符串取出子字符串,并返回,不改變原字符串。與slice作用相同,但有些奇怪的規則,不建議使用 `substring`,優先使用 `slice`。 `indexOf()`和`lastIndexOf()`:確定一個字符串在另一個字符串中的位置,返回一個整數,表示匹配開始的位置。如果返回-1表示沒有匹配到。`indexOf`是從頭部開始匹配,`lastIndexOf`是從尾部開始匹配。 `trim()`:去除字符串兩端的空格,返回一個新的字符串,不改變原字符串。 `toLowerCase()`、`toUpperCase()`:將字符串全部改為小寫或者大寫,返回一個新的字符串,不改變原來字符串。 `search()`:返回匹配的第一位置,沒有找到返回-1。 `replace()`:該方法用于替換匹配的字符串,一般情況下只匹配第一個匹配到的元素。 `split()`:按照給定字符分割字符串,并返回一個由分割字符串分割出來的子字符串數組。 示例 ~~~javascript var s = 'hello'; var ss = new String('hello World'); var aa = new String('aaa'); console.log(typeof ss); console.log(String(true)+1); console.log(String(123)+1); console.log(ss.charAt(9)); console.log(ss.concat(aa)); console.log(ss.slice(0,-1)); console.log(ss.slice(1,-1)); console.log(ss.substring(0)); console.log(ss.substring(1,3)); console.log(ss.slice(1,3)); console.log(ss.indexOf('l'));//9 console.log(ss.lastIndexOf('l'))//2 console.log(ss.trim()); console.log(ss.search('he')); console.log(ss.replace('hello','Hi'));//Hi World var bb = new String('a-b-c-d-e-f-g'); console.log(bb.split('-')); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看