I have a remove[] array which has all the index positions of all the element with 0 in the data array (as below).
data array:
Retail,1,Utilities,1,Fo
My problem was that splice was removing the wrong element from the array. I saw the answer with the while loop but the solution that I made is :
var index = jQuery.inArray(element, arr); arr.splice(index,1);