How to split data to get only specific part – JavaScript

  • A+
Category:Languages

How to split data to get like 2018-07-17 from the following code:

getCompanyHolydayLeave() {   this.props.actions.getCompanyLeaveDetails().then(() => {     if (!this.props.common.getCompanyLeaveDetailsPending) {      const poyaArray= this.props.common.companyLeave       var result = poyaArray.map((poyaArray) => poyaArray.date )      var  xData= result.toString().split("T")       this.setState({ companyLeave:xData });        }   }); } 

My output xdata like this.

0: "2018-04-29"  1: "18:30:00.000Z,2018-05-06" ​ 2: "18:30:00.000Z,2018-05-28" ​ 3: "18:30:00.000Z,2018-06-26" 

I need like this:

0: "2018-04-29"  1: "2018-05-06" 

How can I do so?

 


You can format xData with map():

var xData = ["2018-04-29",  "18:30:00.000Z,2018-05-06", "18:30:00.000Z,2018-05-28", "18:30:00.000Z,2018-06-26"];  xData = xData.map(d => d.split(',')[d.split(',').length-1]); console.log(xData);

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: