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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:47:20+00:00 2026-05-28T19:47:20+00:00

I have two arrays arr1 = new Array(); arr2 = new Array(); If i

  • 0

I have two arrays

arr1 = new Array();
arr2 = new Array();

If i do the following:

arr1 = arr2;

in javascript is this assigning by value or by reference? What i mean is, after doing the above, will further changes in arr2 affect arr1’s content and also the other way around?

  • 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-28T19:47:21+00:00Added an answer on May 28, 2026 at 7:47 pm

    Here is a clone function I wrote…

                /**
             * Clone an Object or Array.
             * 
             * @param {Object}
             *          obj the Object or Array that should be cloned
             * @param {Boolean}
             *          deep if true also clones the elements of an Object or Array,
             *          default is true
             * @return
             * @type Object
             */
            function cloneObject(obj, deep) {
                try {
                    deep = !deep ? false : true;
                    if (obj.constructor === Object) {
                        var nObj = {}, elem = null;
                        for (elem in obj) {
                            if (obj.hasOwnProperty(elem)) {
                                nObj[elem] = deep ? cloneObject(obj[elem]) : obj[elem];
                            }
                        }
                        return nObj;
                    }
                    if (obj.constructor === Array) {
                        var nArr = [], i = 0;
                        for (i = 0; i < obj.length; i++) {
                            nArr[i] = deep ? cloneObject(obj[i]) : obj[i];
                        }
                        return nArr;
                    }
                } catch (e) {
                    console.error("cloneObject(", arguments, ") >", e);
                }
                return obj;
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have these two arrays: string[] arr1 = new string[2]{Hello, Stack} string[]
I have an array of two dimensional Arrays. I want to create a new
I have two arrays: @arr1 = ( 1, 0, 0, 0, 1 ); @arr2
I have two arrays double[] pole=new double[100]; XSSFRichTextString[] pole1=new XSSFRichTextString[100]; array pole I filled
I have two arrays: var arr1 = [1, 2, 3], arr2 = [2, 5,
I have two arrays arr1 and arr2 containing datetime in dd/MM/yyyy HH:mm:ss and HH:mm:ss
I have this array that searches for matches between two arrays. The problem is
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two arrays in PHP. The first array ($author_array) is comprised of user_ids
I have two arrays: Array ( [2005] => 0 [2006] => 0 [2007] =>

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.