1

I want to convert one array to another kind of array. Actually I am using typescript. What am I doing wrong here:

//terminals is an array of objects. 
    groupOptions = terminals.map(trm => {
                id: trm.TerminalID, 
                text: trm.TerminalName, 
                selected: true
            });

intelisence complains about the body of the curly brackets. With them I meant an object, probably intellisence thinks its anonymous method body. How can I workaround this?

Otabek Kholikov
  • 1,188
  • 11
  • 19

1 Answers1

2

Try wrapping the curly brackets with parenthesis like this:

    //terminals is an array of objects. 
    groupOptions = terminals.map(trm => ({
                id: trm.TerminalID, 
                text: trm.TerminalName, 
                selected: true
            }) );

Problem is that the JavaScript runtime picks up the curly brackets as beginning/end of a function.

alamoot
  • 1,966
  • 7
  • 30
  • 50