How to capitalize the first letter of each word in array in Node.js

1 Answer

0 votes
function capitalizeArrayWords(arr) {
  	return arr.map(element => {
    	return element.charAt(0).toUpperCase() + element.substring(1).toLowerCase();
  	});
}

console.log(capitalizeArrayWords(['node.js', 'c++', 'python', 'java']));





/*
run:

[ 'Node.js', 'C++', 'Python', 'Java' ]

*/

 



answered Jun 20, 2022 by avibootz
...