iLTC Home
Bookmark iLTC!
iLTC Google Boards

Google Groups
Receive The Code in Email!



Categories

Perl
  • Perl Tutorials Beginners

    Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

    HTML
  • HTML Tutorials



  • Perl with cheese...
    123,711

    iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Javascript Concat Use Concat to Join Two Arrays in Javascript

    Javascript Concat - Use Concat to Join Two Arrays in Javascript



    i=new Array("Hi", "Hello");
    j=new Array("Aloha", "Goodnight");

    i=i.concat(j);

    document.write(i);

    Which Prints:
    Hi,Hello,Aloha,Goodnight


    -We create an array and name it i because we like one letter variable names.
    -We create an array and name it j because of our previously mentioned love of short names.
    -We use Javascript's built-in concat method on our i array. In the parenthesis, we put what we want added to the end of our i array. In this example, we want to addend the array we named j.
    -We use Javascript's built-in document.write command to print to the browser.

    NOTE: When we used concat on our array i we also stored the results right back into i. We didn't have to. We could have stored the results into a new variable, if we had wanted to. We could have named our new array something clever like k. (Then our code would have looked like the Copy-and-Paste code below.) That would have allowed our i array to retain its original value.


    NOTE: We could have put what we wanted addended to our first array straight into the concat method, inside quotation marks, like so:


    i=new Array("Hi", "Hello");

    i=i.concat("Aloha,Goodnight");

    document.write(i);

    Which Prints:
    Hi,Hello,Aloha,Goodnight



    Free Copy and Paste Javascript Code:

    <script type="text/javascript">
    <!--

    i=new Array("Hi", "Hello");
    j=new Array("Aloha", "Goodnight");

    k=i.concat(j);

    document.write(k);

    -->
    </script>


    Resources:
    Javascript Array - Create an Array in Javascript
    Javascript Join - Use Join to Make an Array into a String in Javascript
    Javascript Splice - Use Splice to Replace Items in an Array in Javascript
    Javascript Slice - Use Slice to Get Items from an Array in Javascript
    Javascript Sort - Use Sort on Items in an Array in Javascript
    Javascript Shift Use Shift to Remove Items from the Beginning of an Array in Javascript
    Javascript Unshift - Use Unshift to Put Items on the Front of an Array in Javascript
    Splitting an Array using Javascript
    Javascript Push - Use Push on an Array in Javascript
    PRINT to Browser with document.write Command in Javascript

    JavaScript Kit - Nice Array Tutorial on Another Site
    Javascript Alert
    onClick Javascript
    Javascript Referrer
    Javascript Reset Form
    Annoy Users with onBlur in Javascript
    Get Query String Using Javascript
    Use innerHTML to Change Text on a Page



    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    Previous Article: Javascript Join Use Join to Make an Array into a String in Javascript
    Next Article: Javascript SetTimeout





    CSSCSS

    Eric Meyer

    New $29.69

    HTMLHTML

    Gary B. Shelly, Th...

    New $84.55

    jQuery in ActionjQuery in Action

    Bear Bibeault, Yeh...

    New $26.39

    CSSCSS

    David McFarland

    New $23.09

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.85

    HTML, XHTML, and CSS, Si...HTML, XHTML, and CSS, Sixth Edition ...

    Elizabeth Castro

    New $23.09

    Bulletproof Web DesignBulletproof Web Design

    Dan Cederholm

    New $23.99

    New Perspectives on HTML...New Perspectives on HTML and XHTML 5...

    Partrick Carey

    New $67.45

    JavaScriptJavaScript

    David Flanagan

    New $31.49


    Of Interest:
  • To Reverse an Array in Perl
  • Create or Put Items into an Array in Perl
  • To See if a Directory Exists in Perl
  • Add to the Beginning of an Array with Unshift in Perl
  • Javascript Reverse - Use Reverse on Items in an Array in Javascript
  • Javascript Shift - Use Shift to Remove Items from the Beginning of an Array in Javascript
  • Getting Epoch Time in Javascript
  • Get String Length with Javascript
  • HTML Center
  • HTML Superscript Text
  • HTML Status
  • Make Strikethrough Text Using HTML

  • More Articles:
  • Write a FOREACH LOOP in Perl
  • Passing a Variable or Value to a Subroutine in Perl
  • OPEN and READ a Data File in Perl
  • Renaming a File with Perl's RENAME Function
  • onClick Javascript
  • Javascript Alert
  • Get Formatted Time in Javascript
  • Javascript Referrer
  • PRINT to Browser with document.write Command in Javascript
  • Javascript Unshift - Use Unshift to Put Items on the Front of an Array in Javascript
  • Make Text Bold Using HTML
  • HTML Superscript Text
  • HTML Font Code
  • Make Strikethrough Text Using HTML

  • Search iLTC w/ Google





    Recent Articles

  • Javascript Focus Form Field
  • Javascript Lowercase Text
  • Javascript Uppercase Text
  • Javascript Superscript Text
  • Javascript Subscript Text
  • Make Text Blink Using Javascript
  • Make a String into a Link in Javascript
  • Javascript Italics Text
  • Javascript Bold Text
  • Javascript Redirect
  • HTML Frames
  • HTML Color Chart
  • HTML Link
  • Javascript Status Bar








  • Perl Programming - Javascript Programming - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006 iLoveTheCode.com


    Contact Chris | About this Site


    420,472
    Counter by iLoveTheCode.com


    Last Modified: Friday, 23-Jun-2006 07:23:15 EDT