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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:10:35+00:00 2026-05-29T11:10:35+00:00

I have this structure: var a = []; a.push({level: 1, column: 4, parent: none,

  • 0

I have this structure:

var a = [];
a.push({"level": 1, "column": 4, "parent": "none", "title": "Node 0", "content": "Parintele suprem", "show": "1"});
var b = a;

a.push({"level": 1, "column": 5, "parent": "none", "title": "Node 1", "content": "Parintele suprem", "show": "1"});

console.log(b);

Now the problem is that b has the exact content as a (the content after the second push). This suggest (correct me if I’m wrong) that when I said b = a I actually gave b same reference as a, so whatever I do in a I have in b. The thing is that I need to pass the value. So I have the previews a, value in b.

Edit to make the question more clear: How do I pass the value instead of the reference?

  • 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-29T11:10:36+00:00Added an answer on May 29, 2026 at 11:10 am

    I think you can use this to copy the value instead of the reference:

    var b = a.slice(0);  
    

    EDIT
    As the comments have mentioned and it’s also mentioned here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/slice

    slice does not alter the original array, but returns a new “one level deep” copy that contains copies of the elements sliced from the original array. Elements of the original array are copied into the new array as follows:

    • For object references (and not the actual object), slice copies
      object references into the new array. Both the original and new array
      refer to the same object. If a referenced object changes, the changes
      are visible to both the new and original arrays.

    • For strings and numbers (not String and Number objects), slice copies
      strings and numbers into the new array. Changes to the string or
      number in one array does not affect the other array.

    If a new element is added to either array, the other array is not affected.

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

Sidebar

Related Questions

I have this menu structure that is used to navigate through content slider panels.
Good day to all. I have this structure <html> <iframe> <div id=idd>Some Content</div> </iframe>
Let's say I have this simple structure class FooDefinition { public FooDefinition Parent {
I have this structure on form, <input type=test value= id=username /> <span class=input-value>John Smith</span>
I have this HTML structure and want to convert it to an accordion. <div
I have this HTML structure (excerpt): <td> <select id=test1 class=pub_chooser> <option value=99>All Publications</option> <option
I have this table structure and would like to map it using Fluent Hibernate
I have this file structure: folderIWantStuffIn/ - old_stuff Now I want to add some
Given that I have this resultset structure (superfluous fields have been stripped) Id |
Okay so, I have this project structure: package A.B class SuperClass (this class is

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.