Question about group isomorphism 
Show that if $f: G \rightarrow H$ is a group isomorphism then $f(Z(G))=Z(H)$, where $Z(K)$ is the center of group $K$

I don't quite understand what it means by $f$ being a group
Approach: It's quite messy,but here is the idea
Let $x\in Z(G)$ and $y \in Z(G)$, $f(xy)=f(x)(y)=f(yx)=f(y)f(x)$
This shows that $f(x)$ can be in the center of $H$, but how do we know $f(y)$ runs all over $H$?. I have no idea. I need help
 A: If $g \in Z(G)$, then $g$ commutes with every element of $G$.  Consequently, by the properties of $f$, $f(g)$ commutes with every element of $H$, therefore $f(g)$ lies in the center of $H$.  So, 
$$
f(Z(G)) \subset Z(H)\quad (1)
$$
Conversely, if $h \in H$ lies in the center of $H$, then $h$ commutes with every element of $H$, and therefore (by the properties of $f^{-1}$) the element $g = f^{-1}(h)$ of $G$ commutes with every element of $G$, and therefore $g$ lies in the center of $G$.  This shows that $f^{-1}(Z(H)) \subset Z(G)$, which implies 
$$
Z(H) \subset f(Z(G)) \quad (2).
$$
The inclusions (1) and (2) together imply the desired result.
A: Let's first show that $f(Z(G)) \subseteq Z(H)$. Let $h \in f(Z(G))$, we want to show $h \in Z(H)$.
Since $h \in f(Z(G))$, then there exists a $g_h \in Z(G)$ such that $f(g_h) = h$. Now let $y$ be any element of $H$. In order to show that $h \in Z(H)$, we need to show that $hy = yh$ by definition of the center of a group. Since $f$ is a bijection, there exists an $x\in G$ such that $f(x) = y$. 
Since $g_h \in Z(G)$, we have for $g_hg = gg_h$ for any element $g \in G$. Notice,
$$f(g_hx) = f(g_h)f(x) = hy$$
and
$$f(g_hx) = f(xg_h) = f(x)f(g_h) = yh$$
and so $hy = yh$ as desired.
Now we show $Z(H) \subseteq f(Z(G))$. Let $h \in Z(H)$. We wish to show that $h \in f(Z(G))$, in other words, that there exists $g_h \in Z(G)$ such that $f(g_h) = h$. Since $f$ is a bijection, there exists a $g \in G$ such that $f(g) = h$ so it remains to show that $g \in Z(G)$ in order for $g$ to be the $g_h$ we desire. Let $x$ be any element in $G$, we must show that $gx = xg$ in order to show $g \in Z(G)$. Since $f$ is a bijection, there exists a $y \in H$ such that $f(x) = y$. Notice that,
$$hy = f(g)f(x) = f(gx)$$
and
$$hy = yh = f(x)f(g) = f(xg),$$
thus $f(gx) = f(xg)$ and by injectivity of $f$, $gx = xg$ as desired.
Since $f(Z(G)) \subseteq Z(H)$ and $Z(H) \subseteq f(Z(G))$, we have that the two sets are equal.
