Javascript – Enumerating key, value pairs in object and converting those that match ISO timestamp format

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?

144 thoughts on “Javascript – Enumerating key, value pairs in object and converting those that match ISO timestamp format”

  1. What i do not realize is in truth how you are now not actually a lot more smartly-appreciated than you may be
    right now. You’re so intelligent. You already know therefore considerably
    when it comes to this topic, made me in my view consider it from a lot of numerous angles.
    Its like women and men don’t seem to be interested until it is something to
    do with Girl gaga! Your own stuffs excellent. Always maintain it up!

  2. Simply want to say your article is as amazing. The clearness in your
    put up is simply spectacular and i could suppose you’re a professional in this subject.
    Well with your permission let me to grasp your RSS feed to stay up
    to date with approaching post. Thank you 1,000,000 and please continue the enjoyable work.

  3. Hi, I think your site might be having browser compatibility issues.
    When I look at your blog site in Chrome, it looks fine
    but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that,
    fantastic blog!

  4. Greate post. Keep writing such kind of info on your site.

    Im really impressed by your blog.
    Hello there, You have performed an excellent job.
    I’ll definitely digg it and in my view recommend to my friends.

    I’m confident they will be benefited from this
    web site.

  5. Excellent blog here! Also your web site loads up very fast!
    What web host are you using? Can I get your affiliate link to
    your host? I wish my website loaded up as quickly as yours lol

  6. Thank you a bunch for sharing this with all folks you really
    know what you are speaking about! Bookmarked. Please additionally discuss with my
    site =). We can have a link exchange agreement between us

  7. Aw, this was a really good post. Spending some time and actual
    effort to create a top notch article… but what can I say… I put things off a lot and never seem to get nearly
    anything done.

  8. I know this if off topic but I’m looking into starting my own blog and was wondering what all is
    needed to get set up? I’m assuming having a blog like yours would cost a
    pretty penny? I’m not very internet smart so I’m not 100%
    certain. Any recommendations or advice would be greatly appreciated.

  9. It’s perfect time to make some plans for the future and it is time to be
    happy. I have read this post and if I could I desire to
    suggest you few interesting things or advice. Perhaps
    you can write next articles referring to this article.
    I wish to read even more things about it!

  10. A fascinating discussion is worth comment. There’s no doubt that that you should publish more about this issue, it
    might not be a taboo matter but generally people do not speak about such issues.
    To the next! Kind regards!!

  11. Fascinating blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple adjustements would really
    make my blog jump out. Please let me know where you got your design. Bless you

    my webpage; coupon

  12. Hello! I know this is somewhat off-topic however I needed to ask.
    Does managing a well-established blog like yours take a large amount of
    work? I am brand new to running a blog however I do write in my journal every day.
    I’d like to start a blog so I can easily share my experience and feelings online.
    Please let me know if you have any kind of recommendations or tips for new aspiring bloggers.
    Appreciate it!


Leave a Comment