Studies of ultracompact H II regions – III. Near‐infrared survey of selected regions