I have an array that has from and to.
I want to create a new array, each of which is a separate object.
For example: I have timeDetail and I want create time
var timeDetail=[{from:12:00:00 ,to:13:00:00}{from:11:00:00 ,to:10:00:00}{from:01:00:00 ,to:02:00:00}]
var time=[{value:12:00:00}{value:13:00:00}{value:11:00:00}{value:10:00:00}{value:01:00:00}{value:02:00:00}]
I did that
this.state.timeDetail.map((i)=>{
var a=i.from;
var b =i.to;
var time=[];
time.push({ Id: time.length+1, Value: a });
time.push({ Id: time.length+1, Value: b });
this.setState({
time :time
})
})
But only the last value is replaced time=[{Id:1,value:01:00:00}{Id :2,value:02:00:00}]
timeDetail.reduce(( time, detail ) => [ ...time, { value: detail.from }, { value: detail.to }], []);