My nationality is Vietnamese and I have a flight heading to Vietnam. I have to transit in New York, Los Angeles, and Shanghai on the way (each will be just max 5 hours). Can I use my valid US B1/B2 visa for transit through those two American cities? What about Shanghai; do I need the transit visa for there also?
A visitor visa is always superior to a transit visa. If you can enter and visit (or reside in) a country, you can also transit there.
So yes, absolutely, you can use your B1/B2 visa.