I have a timestamp in my array that I have removed the UTC letters from and I want to replace the old timestamp with the "new" timestamp(without UTC) Maybe there is an even easier way to do the removing?
So I've tried to loop over my data with .forEach and .map trying to replace it but still haven't figure it out how to exactly do so. I've watched a bunch of Stackoverflow threads about this but haven't found a solution that I get to work....clearly missing something or writing something wrong.
So can anyone guide me how to solve this in the best way?
const data = [
{
timestamp: "2019-03-01 09:00:00UTC",
url: "/blub.html",
userid: "12345"
},
{
timestamp: "2019-03-01 09:00:00UTC",
url: "/cont.html ",
userid: "12346"
},
{
timestamp: "2019-03-01 10:00:00UTC ",
url: "/cont.html ",
userid: "12345"
},
{
timestamp: "2019-03-01 10:30:00UTC",
url: "/ho.html ",
userid: "12347"
}
];
console.log("data", data);
console.log("ex: first data object:", data[0]);
//loop through and grab the timestamp in each object and remove the UTC stamp
const GrabTimeStamp = () => {
data.forEach(function (objects, index) {
const timeStamp = objects.timestamp;
const newTimeStamp = timeStamp.slice(0, 19);
console.log("newTimeStamp:", newTimeStamp, index);
//next step to replace the old timestamp with newTimeStamp
});
};
GrabTimeStamp()
Your code looks fine, just refactor that fragment (best approach to work with
forEach
):and it should work.