Array Method Application
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" ><html><head><meta http-equiv="Content-type" Content="text/html; Charset=utf-8 "><title>Array Method Application</title> <script type="Text/javascript"> varnums=New Array();varnames=New Array(3); names[0]="Tom"; names[1]="Jack"; names[2]="Mike."; names[3]="Alice"; names[4]="Alex";//Two ways to create an array varstus1=New Array("Zhangsan","Lisi","Wangwu");varstus2=["hehe","Heihei","haha","HoHo"]; Names.sort ();//AscendingNames.reverse ();//Invert //for iterating through an array for(varI=0; i<names.length;i++) {Document.writeln (names[i]+" "); } Document.writeln ("<br/>");//foreach The index of the array is obtained. for(varJinchSTUS2) {Document.writeln (j+":"+STUS2[J]); } Document.writeln ("<br/>");//stitch The elements in an array with the specified characters varStr=names.join (","); Document.writeln (str); Document.writeln ("<br/>");//In JavaScript, the index of an array can be a number, or it can be a string varcitys=New Array(3); citys["Nanjing"]="Nanjing"; citys["Beijing"]="Beijing"; citys["Tianjing"]="Tianjin"; for(varCinchCitys) {Document.writeln (c+":"+citys[c]+"<br/>"); } Document.writeln ("<br/>");//Two sets of arrays varGrade=New Array(3); grade["wbs14061"]=New Array("Little Tao","Super brother","Regulation regulation"); grade["wbs14081"]=New Array("Small Friends","Chinese Friends","db Friends"); grade["wbs14091"]=New Array("Little plum.","Puppy dog.","Little Donkey.");//Output All class student information for(varGradenameinchGrade) {Document.writeln (gradename+":") for(varStuinchGrade[gradename]) {Document.writeln (grade[gradename][stu]+" ")} Document.writeln ("<br/>"); } Document.writeln ("<br/>");</script></head><body></body></html>
JavaScript-Array Method application