Javascript for in statement usage.

I don’t know why I forget the syntax for things like this.

var cars = ["Ferrari","Subaru","Mazda"];

for ( var i in cars )
{
    alert( cars [i] );
}

And since objects in Javascript are also associative arrays you can do things like this.

var object = new Object;

object.FirstName = "Harvey"
object.LastName = "Meeker"
object.Hobby = "Cars"

for (var item in object)
{
   document.write(item + " " + object[item] + "
") }

Switching between C#, Javascript and all the rest it’s the simple things my brain dumps out.

Leave a Reply

Your email address will not be published. Required fields are marked *