The highly reactive metals like K,Na,Ca, and Mg are extracted by the electrolysis of their molten chloride.
for example:
Extraction of sodium metal:
Sodium metal is extracted by the electrolytic reduction of molten chloride.
when electric current is passed through molten sodium chloride , it decomposes to form sodium and chlorine gas.
2NaCl(l)-----------------> 2Na +Cl2 (gas).