user8274658
user8274658

Reputation:

Unexpected token , ES6 array

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

Answers (2)

Suren Srapyan
Suren Srapyan

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

llama
llama

Reputation: 2537

Array literal notation uses [] not {}.

Upvotes: 2

Related Questions