I'm trying to populate the lightning menu item in LWC with values from get method in javascript. however I'm stopped with an error
Missing key for element inside of iterator. Elements within iterators must have a unique, computed key value.
I'm attaching the code for reference
import { LightningElement} from 'lwc';
export default class App extends LightningElement {
get menuItemValues(){
[{label :'menu1',
value : 'menu1'},
{label :'menu2',
value : 'menu2'},
{label :'menu3',
value : 'menu3'},
{label :'menu4',
value : 'menu4'},
{label :'menu5',
value : 'menu5'}]
}
}
<template>
<lightning-card title ="Demo on LWC" >
<div class="slds-m-top_large">
<lightning-button-menu icon-name="utility:rows"
alternative-text="Toggle menu">
<template for:each={menuItemValues} for:item="menuvalue" >
<lightning-menu-item
label={menuvalue.label}
value={menuvalue.value}
>
</lightning-menu-item>
</template>
</lightning-button-menu>
</div>
</lightning-card>
</template>
key={menuvalue.value}
to ensure there's a unique value for it.