Step 1: Plan:
Use valence electrons directly.
Step 2: Steps:
The outer shell of A is $4s^2$, giving two electrons to donate. The outer shell of B is $3s^23p^5$, seven electrons, so it needs one. A gives two electrons and each B takes one, so we need two B for each A: $\text{AB}_2$.
Final Answer:
The formula of the ionic compound is $\text{AB}_2$, option (B).
\[ \boxed{\text{AB}_2} \]