Sheriff Ronald Jones said the couple did not mention the baby as the officer searched the car.
"He said he looked back and just happened to see a wee little hand sticking out," Jones said.
The baby was taken to City Hospital to be examined, although she did not appear to have any serious problems, Jones said.
The baby was not admitted, a hospital spokeswoman said. Jones said the child will probably be turned over to the state Department of Human Services.
Jones said the couple - believed to be the baby's parents - were incoherent when officers approached the car.
"I was just in there listening to them talking and it was babbling," Jones said.
Marylayna Lewis, 22, and Kevin Roe, 23, were arrested and charged with possession of a controlled substance and wanton endangerment of a child, Jones said.
Police called the discovery of the suspected heroin a surprise.
Jones said crack and marijuana make up most of the illegal drugs found in the area. "I guess maybe we are going to get the big city things here," he said.
Deputies tested the substance at the scene, but police said they will not know for sure what the substance is until it is further analyzed.
If the find is heroin, the 30 grams recovered from the car would have had a street value of about $3,000, Jones said.
Police confiscated the suspected drugs, Jones said. The substance was divided into small, rectangular-shaped packages.
Jones said the couple may have been living in the car, Jones said.
Lewis and Roe were being held in the Eastern Regional Jail near Martinsburg Friday night on $70,000 bond each.