How to combine splitting data using split function

my data: dat1; split operator

var splitstr =  dat1.split("-");

      

I have split the data from this format

2010 -02-02 to Element 0 = 2010
Element 1 = 05
Element 2 = 22

      

this format. Using the split function,

I want to arrange it like 2010.02.02, how can I do it

+2


a source to share


2 answers


You can just replace -

with ,

:

dat1.replace('-', ',');

      



This will give you: 2010,02,02

0


a source


You can change the original line

var date = "2010-02-02";
var formatted_date = date.replace(/-/g, ',');

      

Note that the flag g

must be used to replace all instances of '-'.



Or you can create a new string from the array you created from the original split

var split_date = date.split('-');
...
var formatted_date = split_date.join(',');

      

0


a source







All Articles