In coffeescript we can do this way:
rows = [
{a: 1}
{b: 2}
]
for row in rows
for k,v of row
alert "#{k}: #{v}"
So why we can’t do that this way?:
for k,v of row for row in rows
alert "#{k}: #{v}"
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You cannot do it that way, but you can invert the inner loop and put the loop construct after the expression:
And, as that inner loop is also an expression, you can also invert the outer loop the same way 😀
The most similar to what you were trying to write is probably this:
Which can be further inlined using another
then(thethenkeyword is usually equivalent to a newline and adding one level of indentation):All of these alternatives generate the same JS code, so picking one or another will not result on degraded performance or anything like that 😀