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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:49:20+00:00 2026-05-27T21:49:20+00:00

Pretty self evident question…When using .push() on an array in javascript, is the object

  • 0

Pretty self evident question…When using .push() on an array in javascript, is the object pushed into the array a pointer (shallow) or the actual object (deep) regardless of type.

  • 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-27T21:49:21+00:00Added an answer on May 27, 2026 at 9:49 pm

    It depends upon what you’re pushing. Objects and arrays are pushed as a pointer to the original object . Built-in primitive types like numbers or booleans are pushed as a copy. So, since objects are not copied in any way, there’s no deep or shallow copy for them.

    Here’s a working snippet that shows it:

    var array = [];
    var x = 4;
    let y = {name: "test", type: "data", data: "2-27-2009"};
    
    // primitive value pushes a copy of the value 4
    array.push(x);                // push value of 4
    x = 5;                        // change x to 5
    console.log(array[0]);        // array still contains 4 because it's a copy
    
    // object reference pushes a reference
    array.push(y);                // put object y reference into the array
    y.name = "foo";               // change y.name property
    console.log(array[1].name);   // logs changed value "foo" because it's a reference    
    
    // object reference pushes a reference but object can still be referred to even though original variable is no longer within scope
    if (true) {
        let z = {name: "test", type: "data", data: "2-28-2019"};
        array.push(z);
    }
    
    console.log(array[2].name);   // log shows value "test" since the pointer reference via the array is still within scope
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem here is pretty self-evident from the resulting JSON array at the bottom.
Question is pretty self explanatory i guess. Here is the code I'm using: function
The question is pretty self-explanatory, I suppose. I am using printf and friends (snprintf
Pretty self explanatory question. Is there any reason to use one or the other?
Question is pretty self explanitory. I want to do a simple find and replace,
I think the question is pretty self explanatory. Anyone done this before? UPDATE :
The question is pretty much self-explanatory. I Googled many sites, many methods, tried many
The title of this question should be pretty self explanatory. I am making an
I think the question itself is pretty self-explanatory. The code is given below -
The following code is pretty self-explanatory and my question is very simple : Why

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.