If $G, A, B$ are groups, it is not true in general that $G\times A\cong G\times B \implies A\cong B$. For instance, $G=\mathbb{Z}\times\mathbb{Z}\times\cdots, A=\mathbb{Z}, B=\{1\}$.
What happens when $G,A,B$ are restricted to be finite? Are there finite groups $G,A,B$ such that $G\times A\cong G\times B$, but $A\not\cong B$?
If $G$ satisfies ACC and DCC (ascending and descending chain conditions) on normal subgroups, which applies when $G$ is finite, then $A \cong B$.
Thais follows from the Krull-Schmidt Theorem, which is moderately difficult to prove.