I am trying to reformat the result of string json On the jQuery AJAX success callback I want to loop over the results of the object and change date type or format from string to date and value also like This is an example ,
var chartData1 = JSON.parse('[{"date":"2018-09-16T00:00:00","value":"10:02"},{"date":"2018-09-17T00:00:00","value":"10:37"},{"date":"2018-09-18T00:00:00","value":"10:25"}]');
I want to format to be like this format
var chartData1 = [{
date: new Date(2018, 9, 16, 0, 0, 0, 0),
value: 10.2
}, {
date: new Date(2018, 9, 17, 0, 0, 0, 0),
value: 10.37
}, {
date: new Date(2018, 9, 18, 0, 0, 0, 0),
value: 10.25
},];
you can use Array.map() to modify the objects in the array like :
var chartData1 = JSON.parse('[{"date":"2018-09-16T00:00:00","value":"10:02"},{"date":"2018-09-17T00:00:00","value":"10:37"},{"date":"2018-09-18T00:00:00","value":"10:25"}]');
var result = chartData1.map(e => ({
date: new Date(e.date),
value: e.value.replace(':', '.')
}))
console.log(result)
</div>