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.8.0_1031]
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

    200810Ratagan0029 2008_0320Dublin0249 2008_0221-25LakeDistrict0056 200910_Wales0075
  • Tags

  • RSStwitter logo

  • Comments