the right way to remove elements and splice from array