Let's Talk about Guys, Girls and Sex
One method that scientists use to figure out what metal ions are present in a compound is the flame test.
In the attached video a science student is demonstrating to Vivek the different colours that are emitted when compounds containing different metal ions are heated on a platinum wire in a non-luminous flame.
When heated, the electrons of the metal ions get excited to a higher energy level. When the electrons fall back to lower energy levels they emit light of specific wavelengths.