JavaScript Array.prototype.map() Guide

JavaScript Logo

Array.prototype.map() – Creates a **new array** by transforming each element. Does not mutate the original array.

๐Ÿ‘‰ Syntax

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

๐Ÿงช Example

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

Comments