I am running the following in node and can't understand why one works and why the other doesn't. Here I have an array s where s = [1, 2, 3, 4]. I want to map each number to an object. I've been trying this for a long time:
s.map(i => {name: i})
which returns a list of undefined.
Finally I realized it worked with parenthesis:
s.map(i => ({name: i}))
This provides the output I want: [ { name: 1 }, { name: 2 }, { name: 3 }, { name: 4 } ]
I feel like there is a JavaScript concept I am not understanding. Why does this not work?