var myArray = ["item1", "item2", "item3"];
var myObject = {key1:"value1", key2:myArray}
//Array is updated, so object is updated
myArray.push("item4"); //myObject.key2 is updated with the item4
console.log(myObject.key2); //Object's array updated with new pushed value
//Object is updated, so array is updated
myObject.key2.push("item5"); //myArray is updated with the item5
console.log(myArray); //Array updated with item5
//If we clear out, however, the object retains the original values
myArray = ["muahahah, everything is wiped out"];
console.log("myArray", myArray); //returns ["muahahah, everything is wiped out"]
console.log("myObject.key2", myObject.key2); //Returns the original items
//If we clear out the array via the object, the array does get updated
myObject.key2 = ["cleared the array from object"];
console.log("myArray", myArray); //returns ["cleared array"]
console.log("myObject.key2", myObject.key2); //returns ["cleared array"]
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!