Novice JavaScript Basic Data Collation 2_ basic knowledge
Source: Internet
Author: User
1.
Using the properties of a variable
<script type= "Text/javascript" >
var txt= "Hello world!"
document.write (Txt.length)
</script>
2.
Converts all letters in a string to uppercase letters.
<script type= "Text/javascript" >
var str= "Hello world!"
document.write (Str.touppercase ())
</script>
3.
JS in a variable to add a hyperlink
<script type= "Text/javascript" >
var txt= "Hello world!"
document.write ("<p> hyperlink is:" + txt.link ("http://www.w3school.com.cn") + "</p>")
</script>
4.
The IndexOf method, where the first occurrence of a specified character in a string is positioned. If you do not find the return-1, case-sensitive
<script type= "Text/javascript" >
var str= "Hello world!"
document.write (Str.indexof ("Hello") + "<br/>")//1
document.write (Str.indexof ("World") + "<br/>")//-1
document.write (Str.indexof ("World"))//6
</script>
5.
Match () method
Use Match () to find a specific character in the string and, if found, return the character.
<script type= "Text/javascript" >
var str= "Hello world!"
document.write (Str.match ("World") + "<br/>")//world
document.write (Str.match ("World") + "<br/>")//null
document.write (Str.match ("worlld") + "<br/>")//null
document.write (Str.match ("world!"))//world!
</script>
6.
The replace () method replaces some characters with some character in a string.
var str= "Visit microsoft!"
document.write (Str.replace ("Microsoft", "W3school"))
7.
Merging two arrays
<script type= "Text/javascript" >
var arr = new Array (3)
Arr[0] = "George"
ARR[1] = "John"
ARR[2] = "Thomas"
var arr2 = new Array (3)
Arr2[0] = "James"
ARR2[1] = "Adrew"
ARR2[2] = "Martin"
document.write (Arr.concat (ARR2))
</script>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.