HTML
<template>
<lightning-card>
<p>Before: {fruits}</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 ForLoopExample extends LightningElement {
fruits = ['Apple', 'Banana', 'Orange', 'Grape'];
fruitsUpperCase =[];
handleLoop() {
for (let i = 0; i < this.fruits.length; i++) {
const fruit = this.fruits[i].toUpperCase();
this.fruitsUpperCase = [ ...this.fruitsUpperCase, fruit ];
}
}
}
Video
Video does not exists.