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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:11:17+00:00 2026-06-02T16:11:17+00:00

I have a small function which adds a returned result to a list of

  • 0

I have a small function which adds a returned result to a list of objects but the problem i have is if there is a certain duplicate it will not allow it – but there are some aspects where duplication occurs and other aspects which do not…

I’ll explain better with example:

var data = {"24":{"16":["172"],"15":["160"]}}

This list of data translates to :

var data = {"X":{"Y":["id"],"Y":["id"]}};

Now im trying to insert new data like this:

    for(var key in result){              
      if(result.hasOwnProperty(key)){  
      data[key] = result[key];     
        }
    }

If you consider grid co-ordinates, in my list of objects, Y cannot be duplicated in the same X and X can not be duplicated at all.

This is example data of “result” that im trying to insert:

{24: {13:[187]}}

Thus turning var data to :

var data = {"24":{"16":["172"],"15":["160"],"13":["187"]}};

Does any one know how i can implement a duplication check for my loop ?

  • 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-02T16:11:18+00:00Added an answer on June 2, 2026 at 4:11 pm
    // Declare this temporary object we'll use later
    var obj = {}
    
    for ( var key in result ){              
        if ( result.hasOwnProperty( key ) ) {
            // If the key already exists
            if ( data[ key ] === result[ key ] ) {
    
                // Empty the temporary object
                obj = {}
                // Loop through the subkeys
                for ( var subkey in result[ key ] ) {              
                    if ( result[ key ].hasOwnProperty( [ subkey ] ) ) {
    
                        // Fill in the temporary object
                        obj[ subkey ] = result[ key ][ subkey ]
                    }
                }
    
                // Add the new object to the original object
                data[ key ] = obj
            }
    
            // If the key doesn't exist, do it normally
            else {
                data[ key ] = result[ key ]
            }
        }
    }
    
    // Now, to be tedious, let's free up the memory of the temporary object!
    obj = null
    

    Something like this should work. If there is a collision, I rebuild the inline object so that I can add it back with all the original and new keys/values.

    PS: the last line is just for fun.

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

Sidebar

Related Questions

I have written a small function, which uses ElementTree to parse xml file,but it
I have small function which will recolor pixels in a Bitmap from a given
Hello every one I have made a small function which takes a pointer to
I have written a small function, which uses ElementTree and xpath to extract the
I have a small perl script ( found here ) which adds command line
I have written a small function in C# which isn't my main launguage so
i have been working on a small demo and i wrote a function which
I have made a small function which should print some InfoPath files. It is
I have a small function which I want to rewrite, so that function is
Hello I have a small function which I use for searching for a users

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.