DEV Community

Discussion on: JavaScript is almost pythonic

Collapse
 
rpalo profile image
Ryan Palo

Do you know if JavaScript has anything approaching comprehension syntax? That would be extra pythonic!

From your "Arrow Function" section:

numbers = [1, 2, 3, 4]
list(map(lambda x: x * 2, numbers))

Generally (and you probably know this), you see this in Python as:

numbers = [1, 2, 3, 4]
[x * 2 for x in numbers]
# => [2, 4, 6, 8]
Collapse
 
zzzzbov profile image
Timothy

Array comprehensions existed briefly but didn't receive enough support to become standardized so they were dropped. I expect they may come back in the future.

Collapse
 
aspittel profile image
Ali Spittel

Yeah, I don't think the syntax was quite as clean as Python's but I love that feature in Python and hope it comes back to JavaScript.