Yes, marijuana can help with loneliness, though it may not be the best way to counter loneliness. Still, as a form of escapism, one's use of marijuana can be helpful. When one is high, one is less likely to notice feelings of loneliness as euphoria sets in. Again, this may not be the best way, but it is a way.
Loneliness is a very subjective word. In my experience, I've come to know and better myself in certain areas with the aid of marijuana. Since loneliness is so often paired with sadness and depression, marijuana has helped me (again, I cannot speak for anyone else) develop and implement creative outlets, which has substantially curbed depression, sadness, and loneliness.