How to get the last N characters of a string in TypeScript

1 Answer

0 votes
const s = "typescript";
  
const N = 5;
  
const lastN = s.slice(s.length - N);
  
console.log(lastN);
  
  
  
    
      
/*
run:
      
"cript" 
      
*/

 



answered Jul 11, 2022 by avibootz
...