JavaScript: Convert last character of each word to uppercase

1 min read
Table of contents

function changeLastCharacterToUpperCase (str) {
return str.split(" ").map( (item) => {
return item.slice(0, -1) + item[item.length - 1].toUpperCase();
}).join (" ");
}
console.log(changeLastCharacterToUpperCase('hello world welcome testing a b javascript'));
Output:
hellO worlD welcomE testinG A B javascripT
0
Subscribe to my newsletter
Read articles from Hari Krishna Anem directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Hari Krishna Anem
Hari Krishna Anem
Full stack developer (ReactJS, NodeJS, JavaScript, PHP, SQL)