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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:38:25+00:00 2026-06-07T13:38:25+00:00

Technically there are no such things as an Associative Array in Javascript. But for

  • 0

Technically there are no such things as an Associative Array in Javascript. But for reasons I can’t avoid, I’ve ended up having t do things such as

var x = [1,2,3];
x.someRequiredProperty = 'some value';

As expected, Javascript being Javascript, it works. But now, how do I make a copy of this ‘array‘ so that I can work on multiple instances of this array without compromising the original?

I’ve tried jQuery $.extend([], x), which doesn’t really give me a new copy. Is there something I’m missing?

  • 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-07T13:38:29+00:00Added an answer on June 7, 2026 at 1:38 pm

    I don’t like the idea of an “associative” Javascript array, since adding properties to an array won’t make sense to JavaScript. For instance, the length property will only count the indexed elements (not the properties), but for(var x in assoc_array) will iterate across indexes of the array as well as the “keys”. So to loop just the array items you’d have to use a full for loop for(var i = 0; i < assoc_array.length; i++)....

    Anyway, a copy function like this will work for your purposes:

    function copy_assoc(arr)
    {
        var out = [];
    
        for(var key in arr)
        {
            if(!arr.hasOwnProperty(key))
            {
                continue;
            }
    
            out[key] = arr[key];
        }
    
        return out;
    }
    

    Here’s a demonstration of it being used: http://jsfiddle.net/DbVV8/3/

    • 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
I know that technically all three ways below are valid, but is there any
There are technically two questions here, but are tightly coupled :) I'm using Hibernate
My question is very simple: is there any way to (programmatically, technically, or manually)
I have following code to remove group from collection. Technically, there should be no
I know it's 'technically' not the best practice to be hard coding strings; but
HI, O.K, not technically a programming question but it's still relevent for this forum
I am looking for (and not sure there is such a thing...) a database
I'm curious if there is way to digitally sign documents (technically any piece of
There are some really good resources on HTML5 on the web such as Dive

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.