28 Feb 2010

Javascript

Posted by gavin

Foreach

Javascript lets you have associative arrays (of sorts), e.g:

var myArray = {
    a : 'val1',
    b : 'val2'
};

If you want to loop over this array, you can use a foreach loop:

for( x in myArray ) {
    alert(myArray[x]);
}

This code will pop up a message box for each entry in the array. Because the key is assigned to the variable x, you can use the key as well as the value.

VN:F [1.9.6_1107]
Rating: 0.0/10 (0 votes cast)
  • Print
  • Add to favorites
  • Facebook
  • StumbleUpon
  • del.icio.us
  • FriendFeed
  • Twitter
  • Digg

Leave a Reply

Message:

  • Browse

    or
  • Latest Content

  • Gallery

    IMG_7064 Showing a little leg IMG_6913 IMG_6715
  • Tags

  • RSS<img src="http://www.gavinwillingham.com/wp-content/plugins/twitter-widget-pro/twitter_logo_s.png" height="21" width="92" alt="twitter logo" />

  • Comments