How to get first letter of each word in a string with TypeScript

1 Answer

0 votes
function getFirstLetters(s : string) {
    const firstLetters = s.split(' ')
                        .map(word => word[0])
                        .join('');

  return firstLetters;
}


const str = "javascript php c++ typescript node.js";
 
console.log(getFirstLetters(str));
  
     
      
      
/*
run:
      
"jpctn"
      
*/

 



answered Feb 15, 2022 by avibootz
...