array problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • theS70RM
    New Member
    • Jul 2007
    • 107

    array problem

    why cant i do this:

    for (var i=0;i < 100; i++)
    myarr[] = "foo" + i;


    i have to use myarr[i] = blah

    any way around this?
  • mrhoo
    Contributor
    • Jun 2006
    • 428

    #2
    myarr[] doesn't refer to anything,
    and myarr[i] does.

    This is another way to populate an array of consecutive integers-
    var myarr=[];
    while(myarr.len gth<100) myarr.push('foo '+myarr.length)

    Comment

    • theS70RM
      New Member
      • Jul 2007
      • 107

      #3
      Originally posted by mrhoo
      myarr[] doesn't refer to anything,
      and myarr[i] does.

      This is another way to populate an array of consecutive integers-
      var myarr=[];
      while(myarr.len gth<100) myarr.push('foo '+myarr.length)

      oh ok, so i was hoping myarr[] = "foo"; would just add to the end of the array like php, but i can just use push instead then (doesnt matter if its at the end or not, just in the array is fine)

      Comment

      • mrhoo
        Contributor
        • Jun 2006
        • 428

        #4
        push adds its arguments to the end of the array.

        Comment

        Working...