let a = [{num:'1'},{num:'2'}];
let b = ['1','2'];
let c = b.map(i=>{num:i});
console.log(a);
console.log(c);
I expected variable c to be identical to a, which doesn't happen. Why is the Object initializer syntax not allowed as I'm using it?
The problem is the classic Javascript one: the contents of your arrow function are being treated as a block, not as a function literal, with num as a label, not as an object key. You need to wrap the literal in brackets () to make it work:
let a = [{num:'1'},{num:'2'}];
let b = ['1','2'];
let c = b.map(i=>({num:i}));
console.log(a);
console.log(c);
({num:i})let c = Array.from({length:2},(o,i)=>({num:i+1}));(Same goes for parentheses around the arrow function though.) For 2 entries it doesn't matter, but for larger quantities it makes life easier. Likely it was just an example, but thought I'd mention it just in case