HTML
<template>
<lightning-card>
<p>Before: {fruits.apple}</p>
<button onclick={handleLoop}>Convert all the uppercase</button>
<p>After: {fruitsUpperCase}</p>
</lightning-card>
</template>
Java Script
import { LightningElement } from 'lwc';
export default class ForInLoopExample extends LightningElement {
fruitsUpperCase =[];
fruits = {
apple: 'red',
banana: 'yellow',
orange: 'orange',
grape: 'purple',
};
handleLoop() {
for (let fruit in this.fruits) {
this.fruitsUpperCase = [ ...this.fruitsUpperCase, fruit.toUpperCase()];
}
}
}
Video
Video does not exists.