Join([separator]) array elements are combined into strings
toString() represents an array as a string
reverse() array inversion-change the original array itself
valueOf() returns the array value
The code copy is as follows:
<html>
<head>
<script type="text/javascript">
var fruits= ["Apple","Dape","Orange"];//It is recommended to define and initialize the array in this way
with(document){
writeeln("<ul>");
writeeln("<li>"+fruits.join()+"</li>");
writeeln("<li>"+fruits.join("--")+"</li>");
writeeln("<li>"+fruits.reverse().join()+"</li>");
writeeln("<li>"+fruits.valueOf()+"</li>");
writeeln("</ul>");
}
</script>
</head>
</html>
toUpperCase()--to uppercase
charAt(index)--refers to a certain character
substring(begin,len)--Truncate string
The code copy is as follows:
<html>
<head>
<script type="text/javascript">
var str="javascript";
var num=1234;
with(document){
writeeln(str.toUpperCase()+"<br>");
writeeln(num.toString().charAt(3)+"<br>");
writeeln(str.substring(0,4)+"<br>");
}
</script>
</head>
</html>
Running results:
The code copy is as follows:
JAVASCRIPT
3
java
indexOf--Judge whether there is a certain character in the string
The code copy is as follows:
<html>
<head>
<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>
</head>
<body>
<input type="text" name="email" >
<input type="button" value="check" onclick="isEmail();">
</body>
</html>
Have you any idea about the native methods of manipulating strings in JavaScript? Many times, these native methods can easily implement the functions we need.