JavaScript array.map() Function

JavaScript Logo

array.map() – Creates a **new array** by executing the callback on every element.

๐Ÿ‘‰ Syntax

newArray = array.map((element, index, array) => {
  return /* transformed value */;
}, thisArg);

๐Ÿงช Example

const prices = [10, 20, 30];
const withGST = prices.map(p => p * 1.18);
console.log(withGST); // [11.8, 23.6, 35.4]

Comments