'Unexpected Token' Syntax Error In Object Returned By Arrow Function
Here is the code in question: const data = results.responses.map((response, idx) => { id: idx+1, name: response.name, email: response.email, comment: res
Solution 1:
In your example JavaScript treats {
and }
as a block statement instead of object literal. Wrap your object in brackets ((
and )
) and it will work.
Corrected code:
const data =
results.responses.map((response, idx) =>
({ id: idx+1,
name: response.name,
email: response.email,
comment: response.comment
})
)
Post a Comment for "'Unexpected Token' Syntax Error In Object Returned By Arrow Function"