OiO.lk Blog javascript JavaScript Split, Split string by last DOT “.”
javascript

JavaScript Split, Split string by last DOT “.”


I’m trying to find the last dot in a string (the string may have multiple dots).
Then, store everything that is before and after the last dot in separate variables.
So, text-1.text-2.text-3.text-4 would split into 2 parts like so: text-1.text-2.text-3 stored in a variable and text-4 stored in a another variable.

Based on other answers, I can only get the text after the last dot like so.

var var1 = "text1.text2.text3";
var result = var1.split('.').pop();
console.log(result);



You need to sign in to view this answers

Exit mobile version