Javascript: foreach

Die er niet is :P

Er is dus geen foreach in Javascript. Jammer want dit geeft meer obvious code:

String[] listNames = listViewNames.GetNames();

for(int x = 0; x < listNames.length; x++)
{
	String name = listNames[i];
	//do something with name
}

wordt...

String[] listNames = listViewNames.GetNames();

foreach(String name in listNames)
{
	//do something with name
}

Er is wel een andere syntax voor het for statement, wat lijkt op foreach

var listnames = listViewNames.GetNames();

for(var index in listNames)
{
	//i is now the index
	var name = listNames[index];
	//do something with name
}

Een extra stap dus, maar het kan handig zijn