violagirl Posted December 16, 2006 Share Posted December 16, 2006 Sorry I messed up the title! I meant to type For...In Statements. Grah.The tutorial on this site says that a for...in statement can be used to loop through the elements of an array or the properties of an object. They gave an example with an array, but I can't figure out how one would use it for objects. Could somebody give me an example? Also, it said that the argument variable could be a named variable, an array element, or a property of an object. Could someone also give an example demonstrating how it would work if you used a property of an object? (this could probably be paired with the example I asked for above, I think) Link to comment Share on other sites More sharing options...
aspnetguy Posted December 18, 2006 Share Posted December 18, 2006 I actually would recomend not using it at all. you can do everything with a regualr for loop. Reason I say this is if you intend to use any JS toolkits or mess around with OO Js and protoyping then these things can cause the for in loops to nto work correctly. Link to comment Share on other sites More sharing options...
violagirl Posted December 18, 2006 Author Share Posted December 18, 2006 Oh, well, that's nice to know! I'd still appreciate the examples, if anyone can give them (if not, quite understandable), but thank you for telling me that! I'll definately keep it in mind! Link to comment Share on other sites More sharing options...
jesh Posted December 18, 2006 Share Posted December 18, 2006 I actually would recomend not using it at all. you can do everything with a regualr for loop. Reason I say this is if you intend to use any JS toolkits or mess around with OO Js and protoyping then these things can cause the for in loops to nto work correctly.Actually, thanks to this post (http://w3schools.invisionzone.com/index.php?showtopic=9628) I now understand one reason you'd want to use a for-in loop. It comes in handy if you need to build a clone method for an object. You can iterate through all the members in the object without having to know what those members are. With the typical for loop, you'd have to know what members an object had before you could iterate through them. Link to comment Share on other sites More sharing options...
aspnetguy Posted December 18, 2006 Share Posted December 18, 2006 never mind that doesn't work... Link to comment Share on other sites More sharing options...
violagirl Posted December 21, 2006 Author Share Posted December 21, 2006 never mind that doesn't work...:blinks: Umm... WHAT doesn't work? Link to comment Share on other sites More sharing options...
aspnetguy Posted December 21, 2006 Share Posted December 21, 2006 I was going to say you could loop through object properties with a regular for loop but I couldn't get ti to work, so I left it alone Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now