I have 2 arrays - collections and settings. IN collections array I need to remove empty arrays but the same index I need to remove from array settings so I write:
$.each(collections, function(index, collection) {
if (collection.length == 0) {
collections.splice(index, 1);
settings.splice(index, 1);
}
});
It works only for the first empty array but if there is more than 1 empty array I got error message:
Uncaught TypeError: Cannot read properties of undefined (reading 'length')
How to remove empty arrays from collections but at the same time to remove the same index from settings array?