Understanding the Use of Array.map() in Javascript


Apply a function on every element of an array and return a new array.

Source Code

let numbers = [1, 2, 3, 4];
let squares = numbers.map(function(num) {
  return num * num;
});
console.log(squares); // [1, 4, 9, 16]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments