Click here to Skip to main content
13,732,774 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
i have an object stored in a var, i push it into an array, i filter through the array and change the some of the values of the object, does the object in the origional var change?

What I have tried:

does filter method make a difference, i have tried using proxies
Posted 13-Dec-17 5:21am
Comments
F-ES Sitecore 13-Dec-17 12:02pm
   
Why don't you just try it for yourself and see?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It will change for object Type
var obj1 = { id: 1, name: 'abc' };
        var obj2 = { id: 2, name: 'xyx' };
        var ary = [];
        ary.push(obj1);
        ary.push(obj2);
        ary[1].id = 3;
        ary[1].name = 'new name';
        alert(obj2.id + ' -- ' +obj2.name); // 3 -- new name
        alert(ary[1].id + ' -- ' + ary[1].name); // 3 -- new name


The values remains same for Primitive Data Types
var a = 1;
      var b = 2;
      var ary = [];
      ary.push(a);
      ary.push(b);
      ary[1] = 3;
      alert(b); // 2
      alert(ary[1]); // 3
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.180920.1 | Last Updated 13 Dec 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100