I have a url like this:
http://example.com/mypage?vendorId=1&vendorId=2&vendorId=3
Using jQuery, how can I get every vendorId
value and put them in an array?
I have a url like this:
http://example.com/mypage?vendorId=1&vendorId=2&vendorId=3
Using jQuery, how can I get every vendorId
value and put them in an array?
In javascript, that's just a string:
var url = 'http://mysite.com/mypage?vendorId=1&vendorId=2&vendorId=3'
var qs = url.split('?')[1];
var parts = qs.split('&');
var arr = [];
$.each(parts, function() {
var val = this.split('=')[1];
arr.push(val);
});
or the short way:
var arr = $.map(window.location.split('?')[1].split('&'), function(e,i) {
return e.split('=')[1];
});
You don't need jQuery for this.
var pairs=location.search.slice(1).split('&');
var vendors=[];
for (i in pairs){
bits=pairs[i].split('=');
if (bits[0]=='vendorId') vendors.push(bits[1]);
}