Join ([separator]) array elements are grouped into strings
ToString () represents an array as a string
Reverse () array inversion--change the original array itself
ValueOf () returns an array value
Copy Code code as follows:
<script type= "Text/javascript" >
var fruits= ["Apple", "pear", "orange"];//recommend this to define, initialize an array
With (document) {
Writeln ("<ul>");
Writeln ("<li>" +fruits.join () + "</li>");
Writeln ("<li>" +fruits.join ("--") + "</li>");
Writeln ("<li>" +fruits.reverse (). Join () + "</li>");
Writeln ("<li>" +fruits.valueof () + "</li>");
Writeln ("</ul>");
}
</script>
toUpperCase ()--capitalization
CharAt (Index)--refers to a character
SUBSTRING (begin,len)--Truncate string
Copy Code code as follows:
<script type= "Text/javascript" >
var str= "JavaScript";
var num=1234;
With (document) {
Writeln (Str.touppercase () + "<br>");
Writeln (Num.tostring (). CharAt (3) + "<br>");
Writeln (str.substring (0,4) + "<br>");
}
</script>
Run Result:
Copy Code code as follows:
indexof--determine if a character exists in the string
Copy Code code as follows:
<script type= "Text/javascript" >
function Isemail () {
var emailvalue=document.getelementsbyname ("email") [0].value;
if (Emailvalue.indexof ("@") ==-1) {
Alert ("Please enter the correct email");
}else{
Alert ("OK");
}
}
</script>
<body>
<input type= "text" name= "email" >
<input type= "button" value= "Check" onclick= "Isemail ();" >
</body>
The small partners are aware of the native methods of manipulating strings in JavaScript, and many times these native methods can simply implement the functionality we need.