Skip to content

Posts from the ‘jQuery’ Category

14
Jul

Using jQuery.each() on a mutating list

Suppose we have a scenario that an array variable (let say ‘master’) contains a list of objects. Each of these objects internally has a reference back to the variable array, so that it’s remove function can remove itself from the owner array.

If we use jQuery.each() to call the remove function on that list, such as:

$.each(master, function(idx, item) {
    item.remove();
});

then it will result with error because we will end up calling the remove function on an object that is already removed. Read more »

Advertisements