This popular sensor made by Sharp produces an analog output that varies from 3.1V at 4cm to 0.3V at 30cm.
The sensor has a Japanese Solderless Terminal (JST) Connector. You can purchase a pre-made cable with connector that mates with this sensor. See 3-pin Cable for Sharp Sensors (30cm) or 3-pin cable w/Male Pin Header for Sharp Sensors (30cm).
For limited period, the sensor comes with a 3-pin cable approx. 20cm.