There is a line like this

var str = ?type=residential&price_type=1&course_type=1 

It is necessary to trim the value to the first ampersand, i.e. the output should be this line. Provided that we do not know the length.

 var str = &price_type=1&course_type=1 

How can i do jquery?

    2 answers 2

    Regular help you:

     var str = "?type=residential&price_type=1&course_type=1"; str = str.replace(/^[^&]+/, ''); // если & нет в строке, вернется пустая строка console.log(str); 

    Or so (if not &, then returns the entire line):

     var str = "?type=residential&price_type=1&course_type=1"; str = str.substring(str.search('&')); console.log(str); var str = "?type=residential+price_type=1+course_type=1"; str = str.substring(str.search('&')); console.log(str); 

      We use the function:

       var str = "?type=residential&price_type=1&course_type=1"; console.log(str.substr(str.indexOf("&"))); 

      • Provided that we do not know the length. Or do you need to count the length first? I think there should be a method without a length - Vlad Shkuta
      • I fixed, now everything works - L. Vadim