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



  • Pass the Javascript, please...
    123,713

    iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Javascript Join Use Join to Make an Array into a String in Javascript

    Javascript Join - Use Join to Make an Array into a String in Javascript



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

    i=i.join(":");

    document.write(i);

    Which Prints:
    Hi:Hello:Cheers:Greetings


    -We create an array and name it i because we don't want to risk typoing a long name.
    -We use Javascript's built-in join method on our array.
    ---Whatever we put in the quotes will be the separator in our new string.
    ---If we put nothing in the parenthesis, commas are inserted by default. See example below.
    -We use Javascript's built-in document.write command to print to the browser.


    Example of empty parenthesis:

    i=new Array("Hi", "Hello", "Cheers", "Greetings");
    i=i.join();
    document.write(i);

    Which Prints:
    Hi,Hello,Cheers,Greetings


    NOTES FOR THE INTERESTED: You may notice that what we just printed to the browser looks the same as if we hadn't used join at all. The subtle difference is, i is now a string not an array.

    If we were to say print i[0] with our new string, it would print H for the first piece of our string or undefined (depends on your browser). Back when i was an array before we applied join to it, printing i[0] would have printed Hi.

    We could use split to turn i back into an array, but that's a whole other article :)


    Free Copy and Paste Javascript Code:

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

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

    i=i.join(":");

    document.write(i);

    -->
    </script>


    Resources:
    Javascript Array - Create an Array in Javascript
    Javascript Concat - Use Concat to Join Two Arrays 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 Splice Use Splice to Replace Items in an Array in Javascript
    Next Article: Javascript Concat Use Concat to Join Two Arrays in Javascript





    Head First HTML with CSS...Head First HTML with CSS & XHTML

    Eric Freeman, Elis...

    New $23.99

    Learning Web DesignLearning Web Design

    Jennifer Niederst ...

    New $26.99

    JavaScriptJavaScript

    David Flanagan

    New $31.49

    HTMLHTML

    Gary B. Shelly, Th...

    New $84.55

    Information Architecture...Information Architecture for the Wor...

    Louis Rosenfeld, P...

    New $26.39

    jQuery in ActionjQuery in Action

    Bear Bibeault, Yeh...

    New $26.39

    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99

    Bulletproof Web DesignBulletproof Web Design

    Dan Cederholm

    New $23.99


    Of Interest:
  • Opening and Reading a Directory in Perl
  • Splitting an ARRAY in Perl
  • To Sort an Array in Perl
  • Matching with a Regular Expression, REGEX, in Perl
  • Close Window with window.close in Javascript
  • Javascript Uppercase Text
  • Make a String into a Link in Javascript
  • If, Else If, and Else in Javascript
  • HTML Font Code
  • HTML Link
  • HTML Space
  • HTML Image

  • More Articles:
  • If, Elsif, and Else in Perl
  • Use chmod in Perl
  • Renaming a File with Perl's RENAME Function
  • Getting Server Time in Perl
  • onClick Javascript
  • Javascript Alert
  • Call your Function in Javascript
  • Write a For Loop in Javascript
  • Passing an Argument or Variable to a Javascript
  • Get Formatted Time in Javascript
  • HTML Forms
  • Make Italic Text Using HTML
  • HTML Superscript Text
  • HTML Color Codes

  • 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,474
    Counter by iLoveTheCode.com


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