What is wrong with this expression?
['a', 'b'].map((x) => {[x]:x})
I'm getting this error:
Uncaught SyntaxError: Unexpected token :
You need to wrap your {}
in ()
, or it will be interpreted as the body of a function:
['a', 'b'].map((x) => ({[x]: x }))
You have enclosed the return value with ()
let result = ['a', 'b'].map((x) => ({[x]: x}));
console.log(result);
whenever you return object from arrow functions you wrap them in paranthesis
['a', 'b'].map((x) => ({[x]:x}))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With