views:

57

answers:

2

Lets be clear, I'm not asking for for(var i in list) I want the key assigned to a variable as well.

+5  A: 

The key is, actually, the only thing that gets assigned:

var value;
for(var key in list) {
    value = list[key];
    // do something with key, value
}
Matchu
You are right indeed. Why I believed the opposite to be true, nfi. Thanks!
jim
A: 

Javascript doesn't have this functionality built into the language. The closest it comes is the for (...in...) syntax that you've already rejected.

Look to your javascript library for this functionality. For example, the ever ubiquitous jQuery's each().

Alan Storm
I think he only rejected it because he misunderstood it.
Matchu
True, but for (...in...) can introduce some weird scoping bugs to your code, and then there's the whole hasOwnProperty weirdness. Plenty of reasons to avoid it even if you understand it.
Alan Storm