Getting next free array index.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    Getting next free array index.

    In php doing the below would assign the value to the next free index
    [php]
    // var $array has indices up to [7]
    $array[] = "foo";

    // $array[8] will now hold 'foo'
    [/php]

    Is there a way to do this in javascript?
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Originally posted by markusn00b
    In php doing the below would assign the value to the next free index
    [php]
    // var $array has indices up to [7]
    $array[] = "foo";

    // $array[8] will now hold 'foo'
    [/php]

    Is there a way to do this in javascript?
    array.push('foo ');

    In PHP too, you can use array_push($arr ay, "foo");

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      Originally posted by hsriat
      array.push('foo ');

      In PHP too, you can use array_push($arr ay, "foo");
      Cheers for that bro!

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by markusn00b
        Cheers for that bro!
        ;)

        good luck . . .

        Comment

        Working...