亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - Doesn't the simplest form of arrow function return an object? map(i => { name: i})
黃舟
黃舟 2017-06-14 10:53:09
0
2
1207

If the arrow function does not use curly braces{}, it is equivalent to returning directly

const arr = [1, 2, 3, 4]
arr.map(i => i) // 1 ,2 ,3, 4

But if I want to return an object, I cannot use the simplest form?

arr.map(i => { a: i}) // [undefined, undefined, undefined, undefined]

Must be enclosed in curly braces

arr.map(i => return {{ a: i}}) //  [Object, Object, Object, Object]
黃舟
黃舟

人生最曼妙的風景,竟是內心的淡定與從容!

reply all(2)
phpcn_u1582

Definitely cannot use {} directly, because the function body is also implemented using {}, which will be considered to have an a:1expression

in the function body.

The simplest way to write it is to wrap it with ()

arr.map(i => ({a: i}))
阿神
arr.map(i => ({ a: i})) 
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template