ES6 for…of Example Program – Replace first letter of String with Uppercase


Below example iterates days array using for…of operation in ES6 and replaces the first character of the day with upper case.

/*
* Programming Quiz: Writing a For…of Loop (1-4)
*/

const days = [‘sunday’, ‘monday’, ‘tuesday’, ‘wednesday’, ‘thursday’, ‘friday’, ‘saturday’];

for (const day of days ){
console.log(day.charAt(0).toUpperCase() + day.slice(1));
}

Below is the Output of the Program:

Sunday

Monday

Tuesday

Wednesday

Thursday

Friday

Saturday