Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JavaScript array merge 
 

In this Tutorial we want to describe you a code that help you in understanding how to merge two different array into one array using Java Script.

 

JavaScript array merge

                         

In this Tutorial we want to describe you a code that help you in understanding how to merge two different array into one array using Java Script. We declare a array variable that is used to store array object. An array component  is accessed by an array expression that consists of an expression whose value is an array reference indicated by subscripts indexing expression enclosed by []. An array with size length of x can be indexed by the integers from 0 to x-1.The document. write prints the elements in an array. The for loop execute the script till the array variable is less than array length.The document. write print the list of element in an array. In the same way we declare another array variable array1 that is used to used to store an array object and each array reference hold the list of element in array1 variable indicated by the indexes. The document.write print the list of element in array.

On clicking a button the function1( )is invoked that include 

1)array.concat(array1) - concatenated the two array and store in a variable c

Finally the document. write print the concatenated array by merging two array.

Arraymerge.html

 <html>
  <head>
   <title>Array Declaration</title>
    </head>
    <body>
      <script language="javascript" type="text/javascript">
        function function1(){
        var c=array.concat(array1);
        document.write("<b>"+"Array after merging is: 
        "
+"</b>"+"<br>");
        document.write("===================="+"<br>");
          for(var i=0;i<c.length;i++){
              document.write(c[i]+"<br>")
                }         
            }     
            var array=new Array();
            array[0]="Girish";
            array[1]="Santosh";
            array[2]="Komal";
            array[3]="Mahendra";
            document.write("<b>"+"Element in the array are 
            "
+"</b>""<br />");
            document.write("=================""<br />");
            for(var i=0;i<array.length;i++){
                document.write(array[i]+"<br>")
            }
      
            var array1=new Array();
            array1[0]="Tewari";
            array1[1]="Kashyap";
            array1[2]="Chaoudry";
            array1[3]="Singh";
            document.write("<b>"+"Element in the array are 
            "
+"</b>""<br />");
            document.write("=================""<br />");
            for(var j=0;j<array1.length;j++){
                document.write(array1[j]+"<br>")
            }
            document.write("<br />");
        </script> 
        
        <button onclick="function1();">Merge Arrays</button>
    </body>
</html>

Output of the program

Download Source Code

                         

» View all related tutorials
Related Tags: java javascript c string oop array ant function script object diff fun io include help load variable sed print loop

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.