encodeURI is Native JavaScript function which encode url .
encodeURI("http://arrayoverflow.com/question/break-nested-loop-in-javascript/271");
//http://arrayoverflow.com/question/break-nested-loop-in-javascript/271
more specific encodeURI
function fixedEncodeURI (str) {
return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']');
}
encodeURIComponent also encode Url
encodeURIComponent("http://arrayoverflow.com/question/break-nested-loop-in-javascript/271");
//"http%3A%2F%2Farrayoverflow.com%2Fquestion%2Fbreak-nested-loop-in-javascript%2F271"
more specific encodeURIComponent
function fixedEncodeURIComponent (str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16);
});
}