The two advantages are:
(i) An electromagnet can produce a strong magnetic field and its strength can be controlled by changing the strength of the current or the number of turns in the coil.
(ii) The polarity of an electromagnet can be changed by reversing the direction of current that flows in the solenoid.