Accepted answer

Looks like your code is modifying the array that is being iterated over. Try this and observe the logs.

$.each(chart.series, function(i,ser) {        
        console.log(i + " / " + chart.series.length);

Observe how the current index i is increasing and your series length is decreasing after each iteration.

0 / 4
1 / 3
2 / 2 << chart.series[2] becomes undefined for chart.series.length=2

At the third iteration, i=2 & chart.series.length=2 => ser=undefined

Proper way to remove all series data from a highcharts chart? provides the right way of doing this. Always remove the series at index 0 if it exists.

while(chart.series.length > 0)

Related Query

More Query from same tag