str[i];

slice(startIndex,endIndex) (开始下标,结束下标)

substr(index,length) (下标处开始,长度)

subString(startIndex,endIndex) (开始下标,结束下标不包含此)

  1. <body>
  2. <script>
  3. var str ="hello";
  4. console.log(str[0]); //h
  5. console.log(str.slice(0)); //hello
  6. </script>
  7. </body>
  1. <body>
  2. <script>
  3. var str ="hello";
  4. console.log(str.substr(0,3)); //hel
  5. console.log(str.substring(0,2)); //he
  6. </script>
  7. </body>