0

I am trying to map Select Menu Options using an array, if array contains "mobile" substring in it, it should render option as Selected else it will render as normal.

But that's not working:

<select>
    {xarray.map((heading, index) => 
        {heading.headingis.toLowerCase().indexOf('mobile') != -1 ?
            <option value="{heading.headingis}" key={index} selected>{heading.headingis}</option>
            :
            <option value="{heading.headingis}" key={index}>{heading.headingis}</option>
        }
    )}  
</select>

It is rendering empty dropdown menu. Is there anything wrong or other way of doing this?

Without condition it is working fine.

P.S. headingis is sub index of array. which may contain Mobile Number, Name etc.

Mayank Shukla
  • 100,735
  • 18
  • 158
  • 142
Noman Ali
  • 3,160
  • 10
  • 43
  • 77

0 Answers0