Monday, 19 August 2013

javascript 'for each in' using array

javascript 'for each in' using array

I was testing out the the for each in construct of javascript using an
array. I know it's recommended for objects. But it turns out that the code
wont work. It outputs nothing. So i tried in in the chrome console and it
said "Unidentified identifier" and the Firefox console said: "SyntaxError:
missing ( after for". I have no idea what's the problem. Any suggestions?
Here is the code:
var cars = ['Ferrari', 'Bugatti', 'Ford', 'Lambo'];
var total = '';
for each(var value in cars)
{
total += value + "--";
}
document.write(total);

No comments:

Post a Comment