Examples of common JS array usage and js Array
This example describes common usage of JS arrays. Share it with you for your reference. The specific method is as follows:
Copy codeThe Code is as follows: <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> application of the array method </title>
<Script type = "text/javascript">
Var arrayFruit = new Array ("apple", "orange", "peach", "bannaner ");
Document. write ("array before sorting <br/> ");
For (var I in arrayFruit ){
Document. write (arrayFruit [I] + "<br/> ");
}
ArrayFruit. sort (); // sorts the Array
Document. write ("sorted array: <br/> ");
For (var I in arrayFruit ){
Document. write (arrayFruit [I] + "<br/> ");
}
Document. write ("string connected after sorting: <br/> ");
Var str = arrayFruit. join ("-");
Document. write (str );
Var strFruit = "apple, bannaner, orange, peach ";
Var tempFruit = strFruit. split (",");
Document. write ("string-separated array <br/> ");
For (var I in tempFruit ){
Document. write (tempFruit [I] + "<br/> ");
}
</Script>
</Head>
<Body>
</Body>
</Html>
This article mainly introduces array traversal and string segmentation. If you are interested, you can test and run it.
I hope this article will help you design javascript programs.