Home > other >  How to use Array.prototype.map ()?
How to use Array.prototype.map ()?

Time:01-05

Hi I have a quick question. I am working on a JavaScript Project and am needing to use.

const array = [1, 4, 9, 16];

const map = array.map(x => x 2);

console.log(map);

Error: missing ) after argument list

CodePudding user response:

I am not able to understand what you want to achieve with that code but if you want to resolve that issue you are missing the operator in between the x [] 2 --> insert the operator like ( ,-,/,*) as per your need.

const array = [1, 4, 9, 16];

const map = array.map(x => x *2);

console.log(map);

CodePudding user response:

You have an error here.

const map = array.map(x => x 2);

Change it as follow.

const map = array.map(x => x * x);

And don't use map as a variable name. It's confusing.

  •  Tags:  
  • Related