I have an array of objects. It had 3 objects
I then deleted them one by one using
arr.splice(0,1)
which I repeated 3 times.
I then added a new object to the (what is supposed to be an empty array)
and printed out the ENTIRE array in console.
As you can see, it IS the only object in the array, but instead of starting with index 0, it starts with index 3. Also, the indexes for 0,1,2 are not there, they are not "null" or anything like it. their gone. What's going on?
This is the actual code for removal. I invoke it 3 times.
this.removeSelected = function () {
//Remove from array
//I have verified that selFramePos=0 many times.
f.splice(selFramePos, 1);
}
This object that I keep in each array slot(Just a bunch of data, nothing special):
Data = {
normal : normData,
imageUrl: selfDefaults.viewport.src,
topLeftX: norm(cf.paper.width, vpo.cx, vpw),
topLeftY: norm(cf.paper.width, vpo.cy, vpw),
width: norm(cf.paper.width, vpo.width, vpw),
height: norm(cf.paper.width, vpo.height, vpw),
rotation: selfRotator.getRotation().rotation,
cropping:
{
shape: selfSelector.getSelection().shape,
tlx: mathUtils.normalize(cf.paper.width, selfSelector.getSelection().left, vpw),
tly: mathUtils.normalize(cf.paper.width, selfSelector.getSelection().top, vpw),
w: mathUtils.normalize(cf.paper.width, selfSelector.getSelection().width, vpw),
h: mathUtils.normalize(cf.paper.width, selfSelector.getSelection().height, vpw),
color: selfSelector.getSelection().color,
opacity: selfSelector.getSelection().opacity
},
filters: null,
transition:
{
type: 'dissolve',
time: 500
},
requireUserInput: true
}
My problem was that I kept creating new array slots with an increasing index number like so:
var i=0
function add2Array () {
arr[i]='something'
i++
}
So every time I called the function, it created a 'unique id' of sort instead of working with indexes and positions.
I fixed it by removing i and just using 'push' instead of arbitrarily increasing indexes.