I am going through the process of creating a bunch of array's , adding elements with push() and getting back a few arrays with a bunch of elements based on the process used to get the elements on the ui.
So i end up with something like this.
[Object, Object, Object]
0: Object
parcels: Array[1]
ref: "IDE25.8.2013.0637548291"
region: "remote"
service: "Early Delivery"
totalPrice: 210
weight: "1"
1: Object
parcels: Array[1]
ref: "IDE25.8.2013.1507892643"
region: "remote"
service: "Saturday"
totalPrice: 135.67
weight: "1"
2: Object
parcels: Array[1]
ref: "IDE25.8.2013.1507432643"
region: "remote"
service: "Saturday"
totalPrice: 115.67
weight: "1"
From what i have learnt in order to "remove" one of the objects you need to add a delete
So i use
delete consignmentsArr[1];
Now i would assume that the delete would delete the array , but it does not. One is left with what is called a sparse array. So the array does not exist in that is cannot be used, in that it's elements and the objects are not defined but it still exists in the index of the group of arrays as an
[Object, undefined × 1, Object]
This however destroys the logic that has been created with the ui elements that display the elements in the other arrays.
I am not really trying to find out how to fix this problem in my application. What i want to know its why is this the default behavior in javascript? Why would a delete not just be a delete as the name implies, and then reorder the index based on the objects that still exist? Why would leaving it as a sparse array be of any benefit in the development process? Also ... why not rename to
sparse consignmentsArr[1];