es6 capital string code example

Example 1: first letter tuUppercase

const string = "tHIS STRING'S CAPITALISATION WILL BE FIXED."
const string = string[0].toUpperCase() + string.slice(1)

Example 2: javascript uppercase string

var str = "Hello World!";
var res = str.toUpperCase();

Example 3: captitalize js

function capitalize2(str) {
  str = str.toLowerCase();

  const arrOfWords = str.split(" ");

  const arrOfWordsCased = [];

  for (let i = 0; i < arrOfWords.length; i++) {
    const char = arrOfWords[i].split("");
    char[0] = char[0].toUpperCase();

    res.push(char.join(""));
  }
  return arrOfWordsCased.join(" ");
}