Page 1 of 1

For... in...

Posted: Sat Aug 06, 2005 12:23 am
by Sacapuss
Hi !

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

Thanx !

Posted: Sat Aug 06, 2005 12:28 am
by feyd
analogous in php is foreach.

it will iterate over an array or object enumerating each property/element

Posted: Sat Aug 06, 2005 12:31 am
by Sacapuss
Thanx for your answer !

Is there an example anywhere ?

Posted: Sat Aug 06, 2005 12:36 am
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'));