How to split a string by last dot in Node.js

1 Answer

0 votes
const str = '3.1415.926.53589.79323.846.264338.3279502.8841971';
 
const lastIndex = str.lastIndexOf('.');
 
const before = str.slice(0, lastIndex);
console.log(before); 
 
const after = str.slice(lastIndex + 1);
console.log(after); 
 
   
   
   
   
/*
run:
   
3.1415.926.53589.79323.846.264338.3279502
8841971
   
*/

 



answered Apr 30, 2022 by avibootz

Related questions

1 answer 130 views
1 answer 123 views
1 answer 105 views
2 answers 127 views
...