How to extract the first letter from each word in a string with TypeScript

2 Answers

0 votes
const s: string = 'typescript programming language';
   
let match_arr: any = s.match(/\b(\w)/g);          
let first_letters: string = match_arr.join(' ');         
  
console.log(first_letters);
 
 
  
/*
  
run:
  
"t p l" 
  
*/

 



answered Mar 18, 2024 by avibootz
0 votes
const s: string = 'typescript programming language';
   
const firstLetters = s
        .split(" ")
        .map(word => word[0])
        .join(" ");           
  
console.log(firstLetters);
 
 
  
/*
  
run:
  
"t p l" 
  
*/

 



answered Mar 18, 2024 by avibootz
...