I'm looking for the best practice for executing encodeURIComponent (or some other function) for every key in array, before joining it to one string.
This could be done with a loop like this:
var dynamicArray = ['uri1', 'uri2', 'hax&%hax'];
var max = dynamicArray.length,
i,
url = '';
for (i=0;i<max;(i++))
{
url += '/' + encodeURIComponent(dynamicArray[i]);
}
alert(url);
/* RESULT: /uri1/uri2/hax%26%25hax */
But I'm looking for something like this (without a loop):
encodeURIComponent(dynamicArray).join('/'); /* This won't work */
encodeURIComponent(dynamicArray.join('/')); /* Can't do this, wrong result */