Say I have an array like this:
let arr = ["1.2.5", "1", "10", "2.0.4", "3.3.3.3"];
What would be the best way to sort this and get result like this:
let arr = ["1", "1.2.5", "2.0.4", "3.3.3.3", "10"];
First I thought of converting each item in the array into 'float' may work but then multiple decimals won't give expected results.
I can also go for a for loop and doing stuff like item.split(".") and then check one by one, but I do not think this is the best way.
Any suggestions, please?
arr.sort(function(a,b){ return a.split('.')[0] - b.split('.')[0]; });