Not sure if this might be a duplicate, but I'm having some problems trying to come up with a better way to move an element to an array filled with arrays of elements.
For instance:
var foo = [
[ {obj: 1}, {obj: 2}, {obj: 3}, {obj: 4} ],
[ {obj: 5}, {obj: 6}, {obj: 7}, {obj: 8} ],
[ {obj: 9}, {obj: 10}, {obj: 11}, {obj: 12} ]
];
If I delete one element specified by arrayIndex, it will delete that element and then move all the controls to the corresponding array. For example, if I remove obj 3, the result is:
var arrayIndex = 0;
var objIndex = 2;
var bar = foo[arrayIndex].splice(objIndex, 1);
Result:
bar = [
[ {obj: 1}, {obj: 2}, {obj: 4}, {obj: 5} ],
[ {obj: 6}, {obj: 7}, {obj: 8}, {obj: 9} ],
[ {obj: 10}, {obj: 11}, {obj: 12} ]
];
Another example may be as shown removing obj 8:
var arrayIndex = 1;
var objIndex = 3;
var bar = foo[arrayIndex].splice(objIndex, 1);
Result:
bar = [
[ {obj: 1}, {obj: 2}, {obj: 3}, {obj: 4} ],
[ {obj: 5}, {obj: 6}, {obj: 7}, {obj: 9} ],
[ {obj: 10}, {obj: 11}, {obj: 12} ]
];
The problem for me is shifting all processing elements to the correct position of the array. Also, I would like to delete an empty array. Where the length of foo will decrease. foo will also be mutated.
Here is my jsfiddle attempt: https://jsfiddle.net/mLw8kncn/1/
Any help would be appreciated.