SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    RTFM ashleyk's Avatar
    Join Date
    Dec 2005
    Location
    Rochester, New York
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple question about variable naming

    what's the syntax for naming a variable on the fly? for example a for loop sitting inside a function:

    Code JavaScript:
     
    for (var i = 0, j = divs.length; i < j; i++) {
    	"item"+i=whatever;  
    }

    where "item"+i evaluates to item1, item2 etc...
    I'd like the variables to be available outside of the for loop as well....

    thanks,
    ---------------------------------------
    Ashley Kennedy
    ---------------------------------------
    how does a designer get roped into writing code?

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use an array for this
    Code:
    var myArray = [];
    
    for (var i = 0, j = divs.length; i < j; i++) {
        myArray[i] = whatever;  
    }


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
  •