> From: Pops > > Is this the only way to iterate through an object? > > for ( x in myObject) { > }
Ultimately, yes. You can use something like $.each() on an object, but it just runs that same for loop internally - see the source code for $.each(). > and how can you remove an field in an object? > > For example: > > var obj = { > x1: 1123, > x2: 212, > x3: 123131 > }; > > I want to remove obj.x2 the obj object to end up with: > > { x1: 1123, x3: 123131} delete obj.x2; or delete obj['x2']; Note that it is not an error if the property doesn't exist, so you don't have to "protect" the delete with code like this: if( 'x2' in obj ) delete obj.x2; // unnecessary precaution -Mike