I started learning Javascript last week and found how Python’s list comprehension can be done in JavaScript. The map function modifies each element in the list (referred to as array in JavaScript) based on another function provided in the map function. Below shows how a particular list comprehension in Python is done in JavaScript.

# In Python, given a list:
x = [1, 2, 3, 4, 5]

# To give another list having elements that are squares of each element of x:
y = [element**2 for element in x]
print(y) # results to [1, 4, 9, 16, 25]
// In JavaScript, given the same list:
var x = [1, 2, 3, 4, 5];

var y = x.map(function(element) {
   return element ** 2;
  }
);
console.log(y); // results to [1, 4, 9, 16, 25]