jquery/javascript merge array with same id

I have these below array result:

[
{"timeNameID":"2","alarmID":"1"},
{"timeNameID":"3","alarmID":"2"},
{"timeNameID":"4","alarmID":"3"},
{"timeNameID":"5","alarmID":"1"},
{"timeNameID":"6","alarmID":"2"},
{"timeNameID":"7","alarmID":"2"},

{"timeNameID":"2","alarmID":"2"},
{"timeNameID":"4","alarmID":"1"},
{"timeNameID":"5","alarmID":"1"},
{"timeNameID":"6","alarmID":"2"},
{"timeNameID":"7","alarmID":"4"}
]

from this JS script:

var post_str = []
$('.alarm1, .alarm2').each(function ()
{
    var timeNameID = $(this).attr('id'),
        alarmID = $(this).find(':selected').val()
                    
        post_str.push({
            'timeNameID': timeNameID,
            'alarmID': alarmID
        });
});
                
alert(JSON.stringify(post_str));

Now I need to merge that array with same timeNameID, to be like this:

[
{"timeNameID":"2","alarmID":"1","alarmID2":"2"},
{"timeNameID":"3","alarmID":"2","alarmID2":""}, //null/empty
{"timeNameID":"4","alarmID":"3","alarmID2":"1"},
{"timeNameID":"5","alarmID":"1","alarmID2":"1"},
{"timeNameID":"6","alarmID":"2","alarmID2":"2"},
{"timeNameID":"7","alarmID":"2","alarmID2":"4"}
]

Is it possible to do that array merge to be like my above expected?

83 thoughts on “jquery/javascript merge array with same id”

  1. First of all I would like to say great blog! I had a quick question that I’d like
    to ask if you don’t mind. I was curious to know how you center yourself and clear your mind before writing.
    I have had a hard time clearing my thoughts in getting my ideas out.
    I truly do enjoy writing but it just seems like the first 10 to 15 minutes are lost just trying to figure out how to begin. Any suggestions or tips?
    Kudos!

    Reply
  2. Whoa! This blog looks exactly like my old one!
    It’s on a completely different topic but it has pretty much the same page layout and design. Outstanding choice of colors!

    Reply
  3. Great blog here! Additionally your site lots up fast! What web host are you the usage of?
    Can I am getting your affiliate link for
    your host? I want my site loaded up as fast as yours lol

    Reply
  4. It’s the best time to make some plans for the future
    and it’s time to be happy. I’ve read this post and if I
    could I wish to suggest you few interesting things or tips.
    Perhaps you could write next articles referring to this article.

    I want to read even more things about it! quest bars
    http://bit.ly/3jZgEA2 quest bars

    Reply
  5. What i do not realize is in fact how you’re now not actually much
    more neatly-favored than you may be right now.
    You’re very intelligent. You recognize therefore considerably in relation to this topic, produced me in my opinion imagine
    it from so many numerous angles. Its like women and men are not interested except it is one thing to do with
    Lady gaga! Your own stuffs outstanding. At all
    times maintain it up! asmr https://app.gumroad.com/asmr2021/p/best-asmr-online asmr

    Reply
  6. Undeniably imagine that which you stated. Your
    favourite justification appeared to be on the
    internet the easiest thing to be mindful of.
    I say to you, I definitely get annoyed whilst other people think about concerns that they plainly don’t recognise about.
    You controlled to hit the nail upon the highest
    and defined out the whole thing with no need side-effects , folks can take a signal.
    Will probably be again to get more. Thank you scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

    Reply
  7. An impressive share! I’ve just forwarded this onto a colleague who had been doing a little homework on this.
    And he actually bought me dinner simply because I
    discovered it for him… lol. So allow me to reword this….

    Thank YOU for the meal!! But yeah, thanks for spending time to talk about
    this issue here on your web page. ps4 games https://tinyurl.com/45xtc52b ps4 games

    Reply
  8. Again artistic news! We have lived in Cloverdale looking for more than 30 years, and in that experience we have every now gone to Cloverdale Pharmasave for much needed information on treating some of our four legged friends, be it the dogs, the horses or uniform the chickens. The staff and pharmacists at http://www.zpackus.com procure usually been our connect with to pro product suggestions and dope on treatment options. we are so appreciative to contain this plenitude of communication so climax and smoothly accessible. Thank you so much!

    Reply
  9. Pingback: clomid nz buy
  10. Pingback: latisse
  11. Pingback: 2mg tizanidine
  12. Pingback: aralen coupon
  13. Pingback: nolvadex otc

Leave a Comment