I am using ArrayList as my array,
let ArrayList = ['a','b','c','d','e','f'];
I am confused in between Method 1 and Method 2 because in both case I Referenced ArrayList by another you can also check logs over this link https://jsfiddle.net/mnjsnj/u1fms8wx/2/
Method 1
let Method1 = ArrayList; // Referenced arrayList by another variable
ArrayList= []; // Empty the array
console.log(Method1); // Output ['a','b','c','d','e','f']
Method 2
let Method2 = ArrayList; // Referenced arrayList by another variable
ArrayList.length = 0; // Empty the array by setting length to 0
console.log(Method2 ); // Output []
No comments:
Post a Comment