capitalize first letter of each word in array code example

Example 1: capitalize first letter in array of strings javascript

for(var i = 1 ; i < newArr.length ; i++){
            newArr[i].charAt(0).toUpperCase();

Example 2: capitalize first letter of each word javascript

const titleCase = function(text) {
  let newText = '';
  text = text.toLowerCase();
  text = text.charAt(0).toUpperCase() + text.slice(1);
  for (let i = 0; i < text.length; i++) {
    if (text[i] === ' ') {
      newText += ' ' + text[i+1].toUpperCase();
      i++;
    } else {
      newText += text[i];
    }
  }
  return newText;
}