'javascript: How to URL encode strings that contain dashes (-)?

I have a string that represents that name of an entity. The name of this entity has a dash in it (-). How can I encode the dash? I believe it should be encoded to '%2D' but when I try encodeURIComponent() or encodeURI() for that matter, it doesn't encode the dash. I was just wondering if there is an encode function that will encode the dash rather than just doing a .replace



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source