An array of JavaScript basics

Source: Internet
Author: User

<script type= "Text/javascript" >//to find the largest number in an arrayvararr=[123,456,789,657,432,564];vararrmax=Getmaxvalue (arr); alert (Arrmax);functionGetmaxvalue (arrint) {varMax=arrint[0];  for(vari=0;i<arr.length;i++)    {        if(Arrint[i] >max) {Max=Arrint[i]; }    }    returnMax;}</script>

Results: 789

Array conversion to string
<script type= "Text/javascript" >var names=["Jing ke Long", "Greetings", "Time Words", "Search Dance", "Merry Christmas"]var named=getName (names); alert (named); function GetName (strName) { var str= ""; for (var i=0; i<strname.length;i++) { str=str+strname[i]+ "|" ; } return str.substring (0,str.length-1);} </script>

Results: Keio | greetings | time words | search Dance | Merry Christmas

 //  Remove object group with ID 1  <script type= " Text/javascript "> var  modjson=[{id:" 1 ", Name:" Wwee ", Addr:" 3qw "},{id:" 2 ",        Name: "User", addr: "KKK"},{id: "3", Name: "We42", Addr: "23ds"  for  (var  i = 0; i < Modjson.length; I++ if  (modjson[i].id = = 1  1); //  }}    Console.info (Modjson);  </script> 
// Array _ Order rollover <script type= "Text/javascript" >var names=["Keio", "Greetings", "Time Words", "Search Dance", "Huahua" GetName (names); alert (names); function GetName (strName) {    var  str;      for (var i=0; i<strname.length/2;i++)     {        str=strname[i];        Strname[i]=strname[strname.length-1-i];        Strname[strname.length-1-i]=str;    }    } </script>

The results are: Huahua, search for dance, time, greeting, Beijing-Silom

//usage of for and in<script type= "Text/javascript" >varmycars=NewArray ("Any", "Mlik", "Yli");varmycars1=NewArray ("DF", "W3", "FGF"); for(vari=0;i<mycars.length;i++) {document.write (Mycars[i]+ "<br/>");} for(xinchmycars1) {document.write (mycars1[x]+ "<br/>")}document.write (Mycars.concat (mycars1) )//The concat () method is used to concatenate two or more arrays. </script>

Results:

Any
Mlik
Yli
Df
W3
Fgf
Any,mlik,yli,df,w3,fgf

<script>varCaser=NewArray ("Who Am I", "who Are You", "who is he");//declaring a variable caser an array type for(vari=0;i<caser.length;i++) {document.write (Caser[i]+ "<br>"); }        varunn=NewArray (); varJ; unn[0]= "123"; unn[1]= "456"; unn[2]= "789";  for(j=0; j<unn.length;j++) {document.write (unn[j]); }    </script>

An array of JavaScript basics

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.