[Home] > Snippets  > Languages  > JavaScript  > Strings  >  Swap case of characters in a string

Swap case of characters in a string

JavaScript

const swapCase = (str) => str
.split('')
.map((c) => (c === c.toLowerCase() ? c.toUpperCase() : c.toLowerCase()))
.join('')

Examples

swapCase('Hello World') // 'hELLO wORLD'