unescape method in javascript

3

I'm having doubts about script below:

function getURLParam(name) {
   var regex = "[\?&]"+name+"=([^&#]*)";

//mais código
   return unescape(results[1]);

I'm new to javascript , I can not understand what this is:

return unescape(results[1]); 
  • What does this part do?
  • Why did you need to use this?
asked by anonymous 29.04.2016 / 18:51

1 answer

4

unescape is a deprecated method, but its function is to transform characters into hexadecimal format into "normal" characters. For example

unescape("%E4%F6%FC");  // dá "äöü"

The return part I assume you know, is what indicates to the function that it should return the value that follows.

The results[1] and var regex = "[\?&]"+name+"=([^&#]*)"; part gives me an idea that you have a .match somewhere and then the [1] is the second element / result of a match which is precisely the value found. Because .match has in the first element of the array that returns the complete string and in the second (and remaining) the result itself.

    
29.04.2016 / 19:00