foo=[];
Creates a new Array without affecting the older reference variables.
foo.length=0;
Creates a new Array by affecting the older reference variables.
Example:
var foo = ['f','o','o']; var bar = ['b','a','r']; var foo2 = foo; var bar2 = bar; foo = []; //Creates a new Array without affecting the reference variable
bar.length = 0; //Creates a new Array by affecting the reference variable var foo3=foo; //Notice the difference for foo2 and foo3
console.log("foo is",foo, "bar is",bar); console.log("foo2 is",foo2,"bar2 is",bar2); console.log("foo3 is:",foo3);
Output:
"foo is" Array [] "bar is" Array []
"foo2 is" Array ["f", "o", "o"] "bar2 is" Array []
"foo3 is:" Array []
Comments
Post a Comment