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



  • I love the code... dot com
    123,727

    iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Javascript Slice Use Slice to Get Items from an Array in Javascript

    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



    Click HERE to comment or discuss at iLoveTheCode GOOGLE Group
    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





    Dreamweaver CS3Dreamweaver CS3

    David McFarland

    New $29.69

    DojoDojo

    Matthew A. Russell...

    New $26.39

    Bulletproof Web DesignBulletproof Web Design

    Dan Cederholm

    New $23.99

    CSSCSS

    Eric Meyer

    New $29.69

    JavaScriptJavaScript

    David Flanagan

    New $31.49

    New Perspectives on Crea...New Perspectives on Creating Web Pag...

    Patrick Carey

    New $69.26

    CSSCSS

    David McFarland

    New $23.09

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.85

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99


    Of Interest:
  • Substitute in Perl
  • Putting Two Strings Together, Concatenate
  • Delete a File Using unlink in Perl
  • Use chmod in Perl
  • Annoy Users with onBlur in Javascript
  • Javascript Status Bar
  • Mimic Typing from a Textfield in a Textarea with Javascript
  • Splitting an Array using Javascript
  • HTML Color Chart
  • HTML Space
  • Make Italic Text Using HTML
  • HTML Body Tag

  • More Articles:
  • Opening and Reading a Directory in Perl
  • Use chmod in Perl
  • Undefine an Array in Perl
  • Matching at the Beginning and End
  • onClick Javascript
  • Javascript Alert
  • Use OnMouseOver in Javascript
  • Javascript Shift - Use Shift to Remove Items from the Beginning of an Array in Javascript
  • Use onMouseOut in Javascript
  • Make Italic Text Using HTML
  • HTML Color Codes
  • HTML Center
  • Make a New Paragraph 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,488
    Counter by iLoveTheCode.com


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