How to get the length of the last word in a string with Node.js

1 Answer

0 votes
const s = "java nodejs go javascript 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
...