When I initialize an array with an object in JavaScript, does the array contain a reference to the object or is it passed by value? -


i using javascript. have object. place object inside array initialize. work on array , value(s) inside it. i'm hoping know if, changing object in array, changing actual object itself? code below.

function dostuff() {     var node = getnode(); //getnode() returns node object     var queue = [node]; //this line question      while(queue.length > 0) {         //add data queue[0]. add queue[0]'s children queue, remove queue[0]     }      return node; }; 

so, when while loop finishes, node pointing changed object, or hold copy of object before put queue?

i appreciate help, many thanks!

you check yourself:

var obj = {a: 1, b: 1}; var arr = [obj]; arr[0].a = 0; alert(obj.a) // result: 0; 

http://jsfiddle.net/pnmxq/


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -