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

  • Home
  • SEARCH
  • 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 9111951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:37:16+00:00 2026-06-17T03:37:16+00:00

i have this array of objects var ArrTdsObjects = []; function TdMaster(id, HeaderTxt, CurrentIndex,

  • 0

i have this array of objects

var ArrTdsObjects = [];

function TdMaster(id, HeaderTxt, CurrentIndex, SortOrder, Width, Color, BgColor) {
    this.id = id;
    this.HeaderTxt = HeaderTxt;
    this.CurrentIndex = CurrentIndex;
    this.SortOrder = SortOrder;
    this.Width = Width;
    this.Color = Color;
    this.BgColor = BgColor;
}
        ArrTdsObjects.push(new TdMaster(
                        CurTdID,
                        CurTdInnerTxt,
                        CurTdCellindex,
                        CurTdSortOrder,
                        CurTdWidth,
                        "color", "bgColor"
                                        )
                            );

after a few object entries have been added to the array

i want to eliminate duplicates of objects that are stored in the ArrTdsObjects based on curTdID

meaning: the first cell in array with same Id will be left out if the higher cell number has that id

how can i eliminate lower index number array items if they exist in higher cell number
meaning the last added items in array will be the ones that will be saved ?

  • 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-06-17T03:37:18+00:00Added an answer on June 17, 2026 at 3:37 am

    Iterate through the array from 0 to array.length and add the objects to a “hash” (read: javascript polymorphic object). Observe:

    var objects = [...];
    var ids = {};
    for (var i = 0; i < objects.length; ++i) { ids[objects[i].id] = objects[i]; }
    // Now empty the list and push the non-duplicated objects back into it
    objects = [];
    // Check hasOwnProperty in case prototypes have been changed
    for (var id in ids) { if (ids.hasOwnProperty(id)) { objects.push(ids[id]); } }
    

    ids can only contain one object per id, so only the last object with id will remain in ids. Thus you are guaranteed to only have on instance of id in your array after this operation.

    There may be better ways to clean up your array, but then there are almost certainly better ways to do whatever you’re trying to do without having to clean up the array in the first place.

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

Sidebar

Related Questions

I have a map array with objects stuffed with variables looking like this: var
Hello i have this method: private function findConnectedNodes(node:Node):Array{ var test_node:Node; var surrounding_nodes:Array = [];
Im constructing an array of objects like this: var postData = []; $.each(selectedFields, function
I have an array of objects, like this: var companies = [ { name
I have this function to sort a JavaScript array of objects based on a
Say I have an array of Employee Objects: var Employee = function(fname, age) {
I have code similar to this filtering entries in an Array of Objects: var
I have this code to sort an array of objects. The data in the
I have an ArrayCollection of objects. I'm passing this array to a horizontallist as
Let's say I have an array of objects [{href: 'some_uri', 'class': 'this-css-class'}, {href: 'another_uri',

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.