3👍
✅
this.eventTypes = this.rawEventTypes && this.rawEventTypes.map(({ type }) => ({ value: type, text: type}))
but what i don’t understand is how come your code(rawType.type) would work if your array is of the form
['item1', 'item2', 'item3']
instead of,
[{ type: 'item1' }, { type: 'item2' }, { type: 'item3' }]
1👍
You can define a function as below and reuse it multiple times.
//rawItems is array of string
//eg: ['item1', 'item2', 'item3']
function getDropdownItems(rawItems) {
var dropdownItems = [];
rawItems.forEach(item => {
dropdownItems.push({value: item, text: item});
});
return dropdownItems;
}
Source:stackexchange.com