I want to encode a string to UTF-8
in JavaScript. In java we use URLEncoder.encode("String", "UTF-8")
to achieve this.
I know we can use encodeURI
or encodeURIComponent
but it is producing different output than URLEncoder.encode
Can anyone please suggest any available JS method that can be used to achieve same output as URLEncoder.encode
.
NOTE: Due to restrictions I cannot use jQuery.