Return the capitalized array

1

Why do not you return the first letter in uppercase?

function LetterCapitalize(str) { 

  var strArray = str.split(' '),maxA = strArray.length,j=0;
  for(;j<maxA;j++){
      strArray[j][0] = strArray[j][0].toUpperCase();
  }
  return strArray.join(' ');       
}
console.log(LetterCapitalize('eduardo sebastian'));

In my code I try to send a string as a parameter and return the first letter of the words in uppercase, but it does not work, why?

    
asked by Eduardo Sebastian 29.09.2017 в 23:02
source

1 answer

2

For good practices never write in a% of entrada in your case str ,

  

by the way when you access a variable char of a string is mode lectura

function LetterCapitalize(str) { 
  var strArray = str.split(' '),maxA = strArray.length,j=0;
  let arrayReturn = [];
  for(;j<maxA;j++){
  
    arrayReturn[j] = strArray[j].charAt(0).toUpperCase() + strArray[j].slice(1);
  }
  return arrayReturn.join(' ');       
}
let miCadena = "mi cadena";
miCadena[0] = "J";
console.log(miCadena);
console.log(LetterCapitalize('eduardo sebastian'));
    
answered by 29.09.2017 / 23:17
source