Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7611063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:34:21+00:00 2026-05-31T01:34:21+00:00

Is this possible to do using jQuery? Lets say I have a list of

  • 0

Is this possible to do using jQuery?

Lets say I have a list of items, with values attached eg:

  1. Item1: 5
  2. Item2: 10
  3. Item3: 20
  4. Item2: 15
  5. Item4: 30
  6. Item2: 25
  7. Item1: 11

How would I remove all duplicates and add the integers from removed duplicates to one entry, with an output as such using jQuery:

  1. Item1: 16
  2. Item2: 50
  3. Item3: 20
  4. Item4: 30

Edit: I’ve found a function to remove duplicates using $.each, but I have no idea where to go from here to store the values per iteration and modify the DOM for the original item.

var seen = {};
$('.variety_name').each(function() {
    var txt = $(this).text();
    if (seen[txt])
        $(this).parent().remove();
    else
        seen[txt] = true;
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:34:23+00:00Added an answer on May 31, 2026 at 1:34 am

    Simple modification of the code you provided (with assumptions about the html):

    <li class="item"><span class="name">Item1</span>: <span class="value">5</span></li>
    <li class="item"><span class="name">Item2</span>: <span class="value">10</span></li>
    <li class="item"><span class="name">Item3</span>: <span class="value">20</span></li>
    <li class="item"><span class="name">Item2</span>: <span class="value">15</span></li>
    <li class="item"><span class="name">Item4</span>: <span class="value">30</span></li>
    <li class="item"><span class="name">Item2</span>: <span class="value">25</span></li>
    <li class="item"><span class="name">Item1</span>: <span class="value">11</span></li>
    

     

    var seen = {};
    $('.name').each( function() {
          var txt = $(this).text();
          if (seen[txt] == undefined) {
              seen[txt] = $(this);
          } else {
              var val = seen[txt].next('.value');
              val.text( parseInt( val.text() ) + parseInt( $(this).next('.value').text() ) );
              $(this).parent().remove();
          }
    });
    

    When you haven’t seen an item, store the object in seen. When you have seen it, add current item’s value to the stored object’s value, and delete the current item.

    Example: http://jsfiddle.net/JyGc9/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this possible using jQuery/PHP? I am looking to have my webpage automatically go
Using JQuery it possible to clone a Div like this and change add a
I'm considering using this jquery utility as a possible solution, but I want to
Hoping that using something like this demo it is possible to drag items within
Is this case possible using JavaScript or jQuery ? When the value of the
I know this is probably possible using Streams, but I wasn't sure the correct
Is this possible? Using SQL Server 2005....... SELECT * FROM Data0304 UNION SELECT *
I know this is possible to be done using javascript, and I presume I
Is it possible to accomplish something like this using linqtosql? select * from table
Is it possible to format price according to rules like this using DecimalFormat in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.