Overview: I have an array (arr) of objects. I need to convert any value in an object that looks like an ISO timestamp to an epoch. I match via regular expression.
I have an object that looks like:
{
assignee: null
color: null
description: "cool object"
id: "12234858"
last_updated: "2021-01-22T15:30:10.495000+00:00"
}
I have some code that does the following:
arr.forEach((item) => {
let regex = /^[+-]?\d{4}(-[01]\d(-[0-3]\d(T[0-2]\d:[0-5]\d:?([0-5]\d(\.\d+)?)?[+-][0-2]\d:[0-5]\dZ?)?)?)?/;
Object.entries(myobject).forEach(([key, value]) => {
if (value !== null) {
if (value.match(regex)) {
value = Date.parse(value) / 1000;
}
}
});
});
The date conversions work while iterating through the key, values of each object, but once the arr.forEach() completes, the values are reset. What is the best way to handle these conversions? Should I map to new object and duplicate?