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 5960501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:50:06+00:00 2026-05-22T18:50:06+00:00

I have an array such as: var aos = [a,a,b,c,d]; and I want to

  • 0

I have an array such as:

var aos = ["a","a","b","c","d"];

and I want to know if I can find duplicates of each index and store them into something such as an arraylist? For instance we start at:

aos[0]

That then checks to see if

a

is found, and it will keep running through the array taking all the elements with that value in index 0 storing them into a list (such as an arraylist or collection) and then removing them from the list. Is this possible?

  • 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-22T18:50:07+00:00Added an answer on May 22, 2026 at 6:50 pm

    var uniq =_.uniq(aos)

    Or a long winded way (ES5) :

    var uniq = aos.reduce(aos, function(memo, val) {
        if (!aos.some(function(elem) { return elem === val; })) {
             return memo.push(val);
        }
    }, []);
    

    And if you want to support ES3 then :

    var uniq = [];
    for (var i = 0, ii = aos.length; i < ii; i++) {
        var contains = false;
        for (var j = 0, jj < uniq.length; j < jj; j++) {
            if (uniq[j] === aos[i]) {
                contains = true;
                break;
            }
        }
        if (!contains) {
            uniq.push(aos[i]);
        }
    }
    

    Store duplicates in a new array:

    var duplicates = _.select(aos, function(val) {
        var true = _.after(2, function() { return true; });
        return _.any(aos, function(elem) {
            return elem === val ? true() : false;    
        });
    });
    

    Live Example

    _.uniq, Array.prototype.reduce, Array.prototype.some, _.any, _.select, _.after

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

Sidebar

Related Questions

I have this array (I know, technically there is no such thing as a
Suppose I have an array such as: var arr = [1, 2, 3]; And
I have such code: var regions = [{'label': 'array', 'value': '1'}]; //default values $(#auto1).select({
I have such JSON array in file var jsonfromfile = [ [Date.UTC(2004, 1, 3),
Say I have an array such as this in Javascript: var cars = {
I have an array of points in unknown dimensional space, such as: data=numpy.array( [[
Let's say I have an array, @theArr, which holds 1,000 or so elements such
VISUAL C++ Question Hi, I have array of 3 elements and I want to
Have an array of chars like char members[255]. How can I empty it completely
I have a model with such field: /** * @var datetimetz * * @ORM\Column(name=effective_from,

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.