jQuery Data Type How to - Remove all dots except the first one from a string








Question

We would like to know how to remove all dots except the first one from a string.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from   w  w  w. java2  s . c  om-->
var input = '1.2.3.4';
var output = input.split('.');
output = output.shift() + '.' + output.join('');
document.writeln(output);

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: