Reputation:
I have the following code.
It is an array but it throws the error:
Uncaught SyntaxError: Unexpected token ,
var counting = {4, 2, 14}.map((x) => {
var add = x + 1;
return x * add;
});
console.log(counting);
Upvotes: 0
Views: 272
Reputation: 68635
You confuse []
array construction with {}
object construction .
var counting = [4, 2, 14].map((x) => {
return x * (x + 1);
});
console.log(counting);
I have removed the extra line of code that simply added one to x
. This makes the code easier to read and maintain.
Upvotes: 3