Would a magnet work in a vacuum or space?

Magnets work because their atoms are aligned in certain orientation so that the magnetic field is not chaos but is organized as ripples around the matter. Such organized electromagnetic field of any nature can exist without any supporting media like air or water. If you think space is vacuum then you are wrong again. There is a lot of black or dark matter (invisible to current scientific equipment) in this universe and lots of particles like cosmic rays emitted by stars and galaxies. So magnets will work regardless of vacuum or space.