How to get first N characters of a string in Node.js

1 Answer

0 votes
const s = "node.js";
  
const N = 4;
    
const firstN = s.slice(0, N)
    
console.log(firstN);
  
  
  
    
      
/*
run:
      
node
      
*/

 



answered Jul 11, 2022 by avibootz
...