iLTC Home
Bookmark iLTC!

Categories

Perl
  • Perl Tutorials Beginners

  • Javascript
  • Javascript Tutorials
  • Javascript Tutorials Beginners

  • HTML
  • HTML Tutorials

  • Command Line
  • Command Line Tutorials

  • How Tos
  • Other Tips and Tricks



  • #!/usr/bin/perl
    1727905

    iLoveTheCode.com

    Javascript Slice - Use Slice to Get Items from an Array in Javascript

    Javascript Slice will create a new array based on the index numbers you specify in the parenthesis.

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

    i=i.slice(0,2);

    document.write(i);

    Which Prints:
    Hi,Hello

    -We create an array and name it i because we like one letter names.
    -We use Javascript's built-in slice method on our array and store it there as well.
    -We use Javascript's built-in document.write command to print to the browser.

    NOTE: Array Index Numbers start at 0 for the first position. In our example, we started at the 0 position and went through to the 2 position. Notice that the 2 position is NOT stored into the array. Think of the second number as a stopping point.

    NOTE: The ending index number is optional. By default, slice will go all the way to the end of the array unless you specify an ending.

    Example:
    i=new Array("Hi", "Hello", "Cheers", "Greetings");
    i=i.slice(2);
    document.write(i);

    Prints:
    Cheers,Greetings

    Since we didn't specify an ending point, slice started at index number 2 (Cheers) and stored everything until there was nothing left to store.


    Free Copy and Paste Javascript Code:

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

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

    i=i.slice(0,2);

    document.write(i);

    -->
    </script>


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





    Previous Article: Javascript Reverse Use Reverse on Items in an Array in Javascript
    Next Article: Javascript Splice Use Splice to Replace Items in an Array in Javascript






    Search iLTC w/ Google




    Recent Articles

  • HTML Font Code
  • Javascript and CSS - Easy Pop Up Help Balloons
  • Use OnMouseOver in Javascript
  • Use onMouseOut in Javascript
  • Use innerHTML to Change Text on a Page
  • Renaming a File with Perl's RENAME Function
  • PRINT to Browser with document.write Command in Javascript
  • Passing an Argument or Variable to a Javascript
  • Opening an Alert Box in Javascript
  • Opening a REMOTE WINDOW in Javascript
  • OPEN and WRITE a Data File in Perl
  • OPEN and READ a Data File in Perl
  • Mimic Typing from a Textfield in a Textarea with Javascript
  • Javascript Reset Form








  • Perl Programming - Javascript Programming - HTML Code - Mac Unix Command Line - Maybe Some PHP - Free Scripts - ILoveTheCode
    All Content © 2006-2009 iLoveTheCode.com


    Contact Chris | About this Site


    1727630
    Counter by iLoveTheCode.com


    Last Modified: Saturday, 10-Jan-2009 05:40:24 EST



    Hosted as well :)
    Home-brewed logo - 1997