As the title says: What is the difference between condensed arrays and literal arrays?
new Array("John", "Bob", "Sue"); // condensed array
["John", "Bob", "Sue"]; // literal array
Are there things I can do with one that I can't do with the other? Or is it the way it is kept in the memory?
No, there is no difference in the produced object, they are the same.
The first is an attempt to satisfy programmers that are use to a "classical" environment where you have to instantiate a "new" Array object.
It should be noted that Arrays in javascript are not a sequential allocation of memory, but objects with enumerable property names and a few extra (useful) methods.
Because of this creating an array of a set length is fairly useless and unnecessary in most (if not all) cases.
var array = new Array(10);
is functionally the same is manually setting the length of your array
var array = [];
array.length = 10;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With