function titleCase(str) {
var arr = str.toLowerCase().split(' ');
var arr2 = [];
for(var i=0; i<arr.length; i++){
arr2.push(arr[i].substring(0,1).toUpperCase()+arr[i].substring(1,arr[i].length));
}
return arr2.join(' ');
}
titleCase("I'm a little tea pot");
No comments:
Post a Comment