I have a challenge with two arrays and a string shown below
var str=offer?;
var names = [channelId, channelId, offerType, offerType, Language];
var values =[647, 763, international, programming, English];
Both arrays are the same size.
I want to create a formatted string like this
final string = offer?channelId=647,763&offerType=international,programming&language=English
This task needs to be achieved using JavaScript.
I attempted it this way:
var namesMatched=false;
for(var i=0; i<names.lengthl; i++){
for(var j=i+1; j<names.length; j++){
if(names[i]==names[j]){
str=str+names[i]+"="+values[i]+","+values[j];
namesMatched=true;
continue;
}
else if(namesMatched){
str=str+"&";
i=names.length-j;
}
else{
str=str+names[i]+"="+values[i]+"&";
break;
}
}
}
However, it is not producing the expected outcome.
Your assistance here would be greatly appreciated.