Reputation: 17
I want to iterate over the data and place the resulting objects in an array in the "data" array. With this implementation, I get a syntax error. What am I doing wrong? Is my approach correct?
const data = [
dictionary.map(item => {
{
key: item.id,
engword: item.title,
rusword: item.body,
tags: 'beginner',
}
})
];
Upvotes: 0
Views: 35
Reputation: 1743
The .map()
method returns an array, so you should assign it's value to data
variable like this:
const data = dictionary.map(item => (
{
key: item.id,
engword: item.title,
rusword: item.body,
tags: 'beginner',
}
));
Also, you have double curly braces in your arrow function. When returning an object literal like that, you should wrap it in parentheses.
Upvotes: 3