Do you know why you get a spark when you unplug a hair dryer? It's not because of the mains voltage, which is only 120 to 240 V. The spark is actually caused by a sudden change in the magnetic field. When you pull out the plug, the current stops flowing, and the magnetic field drops to zero. This makes nature try to compensate, and it creates a high voltage that ionizes the air and makes a spark.
But this same effect can be useful. A charger uses a similar principle to take high voltage mains electricity and turn it into smooth low voltage DC for your phone or laptop. To do this, the current is switched on and off hundreds of thousands of times per second using transistors. This creates little pulses of electricity that need to be smoothed out.
That's where an inductor comes in. It's like a shock absorber that resists sudden changes in current. When the current rises, it stores energy in a magnetic field, and when the current falls, it releases that energy again. This helps turn choppy electrical pulses into steady DC.