Reputation:
I have a app dropdown.
private appDropdownOptions: IDropdownOption[]
I am assigning value to app dropdown from appItems
.
this.appDropdownOptions = appItems.map(app => {
return { key: app.appModuleIdUnique, text: app.name };
});
This is working fine , but i want to insert one default value on index
0.
{ key: this.appNoSelectionKey, text: 'Select' }
So how i can achieve it.
Upvotes: 1
Views: 304
Reputation: 2570
You can add one default value at 0
index
and rest of appItems
using spread operator like below:
this.appDropdownOptions = [{ key: this.appNoSelectionKey, text: 'Select' }, ...appItems.map(app => { key: app.appModuleIdUnique, text: app.name})]
Upvotes: 1
Reputation: 1188
this.appDropdownOptions = appItems.map((app,index) => {
if(index===0){
return { key: this.appNoSelectionKey, text: 'Select' }
}
return { key: app.appModuleIdUnique, text: app.name };
});
Upvotes: 0
Reputation: 21
Try unshift
method
this.appDropdownOptions = appItems.map(app => {
return { key: app.appModuleIdUnique, text: app.name };
});
this.appDropdownOptions.unshift({ key: this.appNoSelectionKey, text: 'Select' });
Upvotes: 0