解析错误,意外标记 Javascript

Parsing error, unexpected token Javascript

以下是我的代码,它给出了解析错误 -

代码-

const { dataArr, anotherDataArr } = this.props.data
const myArr1 = dataArr.map(item => {'label': item.name,'value': item.code})
const myArr2 = anotherDataArr.map(item => { 'label': item.name, 'value': item.code})

this.setState({
    newArr1: myArr1,
    newArr2: myArr2,
})

myArr1、myArr2 应该是一个对象数组,但我遇到了解析错误。让我知道我在这里犯了什么愚蠢的错误。

当您需要隐式 return 来自箭头函数的对象时,将该对象包装在 () 中。用 () 包裹将使 make 对象表达式。没有 () {} 将被视为块。

根据Returning object literals

The code inside braces {} is parsed as a sequence of statements

Remember to wrap the object literal in parentheses().

const myArr1 = dataArr.map(item => ({'label': item.name,'value': item.code}))
const myArr2 = anotherDataArr.map(item => ({ 'label': item.name, 'value': item.code}))