Swapcase string

JavaScript, String · Nov 15, 2020

Creates a string with uppercase characters converted to lowercase and vice versa.

const swapCase = str =>
  [...str]
    .map(c => (c === c.toLowerCase() ? c.toUpperCase() : c.toLowerCase()))
    .join('');
swapCase('Hello world!'); // 'hELLO WORLD!'

More like this

  • Map string

    Creates a new string with the results of calling a provided function on every character in the given string.

    JavaScript, String · Oct 21, 2020

  • String to character array

    Converts a string to an array of characters.

    JavaScript, String · Oct 8, 2020

  • CSV to JSON

    Converts a comma-separated values (CSV) string to a 2D array of objects. The first row of the string is used as the title row.

    JavaScript, String · Jan 30, 2022