The magnetic field produced by a straight wire is circular in shape and weak in strength. That's why it is of no use. But the magnetic field produced by a coil of many turns is similar in shape and stronger in strength than the field produced by a bar magnet. This magnetic field can be used for various purposes as well. Therefore, a coil of wire is used in an electromagnet instead of just a straight wire.