I'm using react-select and want to loop through an object to represent it as the select's value and label:
// Inside the component's render:
var myVar = [
this.props.foo.forEach(function(a){
{value: a.name, label: a.name} // line 83
})
];
//return
<Select ref="stateSelect" options={myVar} simpleValue clearable={this.state.clearable}
name=""
value={this.state.bar} onChange={this._myFunc}
/>
this._myFunc is not relevant for this question. I want to get something like this:
var myVar = [
{value: "hello", label: "world"},
// the list goes on
];
With the above code, I got:
Parse Error: Line 83: Unexpected token :
I'm not that strong with JavaScript to figure out this solution but is this possible? Links to read up on?
{ ... }is considered as block here. Probably you needsomeObj = {value: a.name, label: a.name}