I'm trying to split this string
"http://localhost/webproject/products.html?product=Apple%20iPhone%206%20With%20FaceTime%20class="
to this
"Apple iphone 6 with Facetime"
but my code only splits it to
"Apple iphone 6 with Facetime class"
and when I'm trying to remove the class word and alert the string, it appears as empty. When I alert split5 it appears as NaN
var url = window.location.href;
var split = url.split('=');
var split2 = split[1];
var split3 = split2.replace(/20/g,"");
var split4 = split3.replace(/%/g, " ");
var split5 = split4.count-5;
var split6 = split4.slice(0, split5);
alert(split6);
split4.count? You meansplit4.length?var split2 = decodeURI(split[1]);productandclassare meant to be separate arguments, there should be a&between them that you can.split()on first.