Radar (radio detection and ranging) uses electromagnetic waves (typically of the radio or microwave region of the spectrum) to detect the presence of remote objects along with other properties including the object's range and angular location relative to the radar.
Sonar (sound navigation and ranging) is a similar technique to radar, but uses sound waves (rather than electromagnetic). As a consequence, sonar required a medium for sound waves to propagate in, typically water or air.
There is also Lidar (light detection and ranging) which, like radar, operates with electromagnetic waves but in the optical portion of the spectrum.
Of the three of these, radar and lidar are suitable for spacecraft as their electromagnetic signal do not require a medium to propagate in. Sonar, requiring some contiguous material for both the sonar system and any targets to be immersed in, would be unsuitable in the vacuum of space.