Given a string
\'1.2.3.4.5\'
I would like to get this output
\'1.2345\'
(In case there are no dots in the
var i = s.indexOf("."); var result = s.substr(0, i+1) + s.substr(i+1).replace(/\./g, "");
Somewhat tricky. Works using the fact that indexOf returns -1 if the item is not found.
indexOf