This
let array_of_objects_containing_two_properties = Array.from({length:100}, _=>{ one:0, two:0})
should work. But it doesn't. It writes the error "Uncaught SyntaxError: Unexpected token ':' "
This
let array_of_objects_containing_two_properties = Array.from({length:100}, _=>{ one:0, two:0})
should work. But it doesn't. It writes the error "Uncaught SyntaxError: Unexpected token ':' "
When an arrow function body starts with {
then it is parsed as a {
StatementList
}
.
{ one:0 }
on its own is parsed as a block with the label "one".
To use an object literal here it must be wrapped in parentheses:
_=>({ one:0, two:0})