October 27, 2024
Chicago 12, Melborne City, USA
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

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video