itz basically acc 2 prefrential discharge theory.........according to this theory “If more than one type of ion is attracted towards a particular electrode, then the ion is discharged one which requires least energy or ions with lower discharge potential or which occur low in the electrochemical series".
For cations : Li+, K+, Na+, Ca2+, Mg2+, Al3+, Zn2+, Fe2+, Ni2+, H+, Cu2+, Hg2+, Ag2+, Au3+
For anions : SO42–, NO3–, OH–, Cl–, Br–, I–.