SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    webality...dunno what it means bcp_2005's Avatar
    Join Date
    Jun 2002
    Location
    Huntsville Alabama
    Posts
    394
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Having some trouble. Probably simple answer...

    Hey I've built an array like this:

    var divs = new Array();
    divs[0] = "divs1";
    divs[1] = "divs2";
    divs[2] = "divs3";
    divs[3] = "divs4";

    What if I wanted to display all the data in the entire array? How would you do this?

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for(var i = 0; i < divs.length; i++)
    {
    document.write divs[i] + "<br>";
    }

  3. #3
    webality...dunno what it means bcp_2005's Avatar
    Join Date
    Jun 2002
    Location
    Huntsville Alabama
    Posts
    394
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha. Simple answer to a simple question. Thanks man...

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you could make a method
    Code:
    Array.prototype.dump = function( type ) {
        var str = "";
        for ( var i = 0; ( x = this[i] ); i++ ) {
            str += i + ": " + x + ( type == 1 ) ? "<br>" : "\n";
            }
        ( type == 1 ) ? document.write( str ) : alert( str );
        }
    
    var divs = new Array();
    divs[0] = "divs1";
    divs[1] = "divs2";
    divs[2] = "divs3";
    divs[3] = "divs4";
    
    divs.dump(0); // alerts data
    divs.dump(1); // writes data to page
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •