programming-examples/js/Functions/Write a JavaScript function that accepts a string as a parameter and converts the first letter of each word of the string in upper case..js
2019-11-15 12:59:38 +01:00

13 lines
462 B
JavaScript

//Write a JavaScript function that accepts a string as a parameter and converts the first letter of each word of the string in upper case.
function uppercase(str)
{
var array1 = str.split(' ');
var newarray1 = [];
for(var x = 0; x < array1.length; x++){
newarray1.push(array1[x].charAt(0).toUpperCase()+array1[x].slice(1));
}
return newarray1.join(' ');
}
console.log(uppercase("the quick brown fox"));