Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 149822

Case while working with a number of version format

$
0
0

When i get a number in the format of version Example "1.0.0.0".If i need to increment to the next version of the number and that would result in "1.0.0.1"

using the below code of regex will get the perfect result as "1.0.0.1"- increment of version

let version = "1.0.0.0";
let nextVersion = version.replace(/.$/, parseInt(version[version.length - 1], 10) + 1);

console.log(nextVersion)

But, if I get a number as "1" not in a format of version but I would expect the same result as above to be "1.0.0.1".How would I deal with a number in this case? if a number is "22" I would expect it to be "22.0.0.1"


Viewing all articles
Browse latest Browse all 149822

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>