How to get the length of the last word in a string with TypeScript

1 Answer

0 votes
const s = "java c go typescript rust";
  
let arr = s.split(" ");
  
console.log("The length of the last word is: " + arr[arr.length - 1].length);
   
   
  
   
/*
run:
  
"The length of the last word is: 4" 
  
*/
    
    
      

 



answered May 5, 2024 by avibootz
...