You can not remove the object in array while in loop. You should create a new array with existing array ...
stackoverflow.com