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
    142,981

    iLoveTheCode.com
    Javascript > Javascript Tutorials How To Easy > Javascript Splice Use Splice to Replace Items in an Array in Javascript

    Javascript Splice - Use Splice to Replace Items in an Array in Javascript



    Javascript Splice looks more complicated than it is.

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

    i.splice(2,1,"LOOK HERE","HIYAS","BYE");

    document.write(i);

    Which Prints:
    Hi,Hello,LOOK HERE,HIYAS,BYE,Greetings


    -We create an array and name it i because we like short names.
    -We use Javascript's built-in splice method on our array.
    -In the parenthesis:
    ---The first number is the Index Number where we want to start making changes to our array.
    ---The second number is how many items we want removed.
    ---Anything after the second number is what we want inserted in place of the removed items.
    -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 2 position (Cheers) and then said remove 1 item. Then we put three items into our array. We put them in caps so they would stand out.


    Free Copy and Paste Javascript Code:

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

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

    i.splice(2,1,"LOOK HERE","HIYAS","BYE");

    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 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 Slice Use Slice to Get Items from an Array in Javascript
    Next Article: Javascript Join Use Join to Make an Array into a String in Javascript





    CSSCSS

    David McFarland

    New $23.09

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

    Elizabeth Castro

    New $23.09

    CSSCSS

    Eric Meyer

    New $29.69

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

    Louis Rosenfeld, P...

    New $26.39

    HTML & XHTMLHTML & XHTML

    Chuck Musciano, Bi...

    New $29.99

    CSS MasteryCSS Mastery

    Andy Budd, Simon C...

    New $23.85

    Learning Web DesignLearning Web Design

    Jennifer Niederst ...

    New $26.99

    JavaScriptJavaScript

    David Flanagan

    New $31.49

    New Perspectives on HTML...New Perspectives on HTML, XHTML, and...

    Patrick Carey

    New $69.26


    Of Interest:
  • Combine, Put Two Arrays Together in Perl
  • What's in an Array, Index Numbers
  • To Reverse an Array in Perl
  • Create a Subroutine in Perl
  • Exit a For Loop in Javascript with Break
  • Opening a REMOTE WINDOW in Javascript
  • Make Text Blink Using Javascript
  • Javascript Lowercase Text
  • HTML Frames
  • HTML Space
  • HTML Center
  • HTML Background

  • More Articles:
  • To Reverse an Array in Perl
  • Write a WHILE LOOP in Perl, Carefully
  • What's in an Array, Index Numbers
  • Exit a Loop with Last
  • Javascript Alert
  • onClick Javascript
  • Javascript Unshift - Use Unshift to Put Items on the Front of an Array in Javascript
  • Mimic Typing from a Textfield in a Textarea with Javascript
  • Setting a Cookie using Javascript
  • Reading Cookies using Javascript
  • Make a Line Return Using HTML
  • HTML Font Code
  • HTML Forms
  • HTML Tables

  • 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


    439,746
    Counter by iLoveTheCode.com


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