javascriptfor-comprehension

What does an array literal with the `for` keyword inside mean in JavaScript?


var names = [name for(name in generateNames(product))];

generateNames just returns an array of column names for various properties in a product.

But what is the whole name for name in thing?


Solution

  • That's an array comprehension.

    It's a new feature of Javascript 1.7, and works like Python's list comprehensions.