1.indexof()メソッド、前から背面への文字列位置を見つけ、ケースに敏感であり、0からカウントされます。同様に、lastIndexof()メソッドは背面から前面にあり、同じ検索条件の2つのメソッドの出力結果は同じです。
例えば:
コードコピーは次のとおりです。
<script type = "text/javascript">
var str = "hello world!"
document.write(str.indexof( "hello"))// output 0
document.write(str.indexof( "world"))//出力6
document.write(str.indexof( "world"))// output-1
</script>
2.長さ、「xxx.length」の形でアクセスします。これは、文字列オブジェクトの方法であるため
コードコピーは次のとおりです。
<script type = "text/javascript">
var str = "hello world!"
document.write(str.length); // output 12
</script>
3.Substr()メソッド、文字列インターセプト、必要なパラメーター、オプションのパラメーターに使用され、0からカウント
コードコピーは次のとおりです。
<script type = "text/javascript">
var str = "hello world!"
document.write(str.substr(3)); // output lo world!、ordinal番号3の文字(序数3の文字を含む)から始まり、パラメーターが1つしかない場合、最後まで出力されます
document.write(str.substr(3,7)); //出力lo world。最初のパラメーターが負の数字の場合、それは逆数です。
</script>
4.Charat()メソッドは、指定された位置で文字を返すために使用され、0からカウントされます。
コードコピーは次のとおりです。
<script type = "text/javascript">
var str = "hello world!"
document.write(str.charat(1)); //出力e
</script>
5.split()メソッド、文字列を文字列配列に分割するために使用されます
コードコピーは次のとおりです。
<script type = "text/javascript">
var str = "hello world!"
document.write(str.split( "")); // output hello、world!
document.write(str.split( "")); // output h、e、l、l、o、w、o、r、l、d、!
document.write(str.split( ""、1)); // output hello
"2:3:4:5" .split( ":")//それは["2"、 "3"、 "4"、 "5"を返します]
"| a | b | c" .split( "|")//それは["" "、"、 "、" b "、" c "を返します。
var words = cente.split(// s+/)//正規表現を分割パラメーターとして使用します
</script>