Skip to main content

Command Palette

Search for a command to run...

JavaScript: Convert last character of each word to uppercase

Updated
1 min read
JavaScript: Convert last character of each word to uppercase
H

Full stack developer (ReactJS, NodeJS, JavaScript, PHP, SQL)

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

Execute above code here

More from this blog

E

Everyday Dev Patterns

26 posts

A collection of real-world JavaScript snippets, patterns, and gotchas from my day-to-day work.