I am getting an array of response from an api. Below is the response array.
[{created by:"user1",updateddttm:
2022-01-20T07:31:35.544Z},
created by:"user2", updateddttm:
2022-02-20T09:31:37.544Z}
From the above response I want to split "updateddttm" (date and time) for each user and save it to the same array as "date", " time" like below.
[{created by:"user1",date:
2022-01-20, time:07:31:35},
created by:"user2", date:
2022-02-20, time: 09:31:37}
Thanks in adv.
I am using Angularjs.
CodePudding user response:
Please find below a possible solution.
const response = [{createdBy:"user1",updatedDttm:'2022-01-20T07:31:35.544Z'},
{createdBy:"user2", updatedDttm: '2022-02-20T09:31:37.544Z'}].map(x => ({
createdBy: x.createdBy,
date: new Date(x.updatedDttm).toLocaleDateString(),
time: new Date(x.updatedDttm).toLocaleTimeString(),
}));
console.log(response);
