For... in...

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Sacapuss
Forum Commoner
Posts: 40
Joined: Mon May 16, 2005 9:46 pm
Location: Earth...

For... in...

Post by Sacapuss »

Hi !

Could you remind me the use of 'for... in...' ?

Thanx !
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

analogous in php is foreach.

it will iterate over an array or object enumerating each property/element
User avatar
Sacapuss
Forum Commoner
Posts: 40
Joined: Mon May 16, 2005 9:46 pm
Location: Earth...

Post by Sacapuss »

Thanx for your answer !

Is there an example anywhere ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

untested

Code: Select all

var buf = new Array();
for(var i in window)
{
  buf[buf.length] = 'window[' + i + '] = ' + (typeof(window[i]) == 'string' ? '"' + window[i].replace('\\','\\\\').replace('"','\\"') + '"' : window[i].toString());
}
alert(buf.join('\n'));
Post Reply