Look at a packet. I don't duplicate the web so here's one I used.

https://en.wikipedia.org/wiki/Ethernet_frame

Notice that at that step, it's not an IP Packet? A lot happens to get from IP packets to Ethernet packets. Once you get that layer under your belt, then you'll understand how the MAC address is used by the switch.

Also, google "What is the difference between a network hub and switch?" This is not a new question but one with many answers which you can choose the one that makes sense to you. I can't hold a class here to see which diagram that sinks in so let's use the power of the web here.