'The task we must set for ourselves is not to feel secure, but to be able to tolerate insecurity' (Erich Fromm).
The function of anxiety, from an evolutionary point of view, is to prime our bodies to either fight, run away (flight), or freeze (so as to hide from predators). Thankfully, most of us do not have to contend with the real threat of death from a predator, or any other serious threat to our physical safety. However, we still react to any perceived threat as if our life depends upon it. That is why we feel anxiety. Of course, the psychology of anxiety is much more complicated than this single psychological model, and includes lots of other psychological processes which differ depending on the type of anxiety the person is experiencing (such as social anxiety, phobias, generalised anxiety disorder, and subtypes of anxiety, including OCD). Even so, it can be useful to understand why we have evolved to experience anxiety, because it reminds us of the fact that in most situations, we are much safer than we feel.