JSFiddle - React, Tailwind, and code Playground
JavaScript
// groups all parameters together into a dictionary-type object
function getUrlParameterGroups()
{
// fake url to work with fiddle
var sPageURL = 'feature_filters[]=&feature_filters[]=on&feature_filters[]=on&x=1';
//var sPageURL = window.location.search.substring(1);
var paramGroups = {};
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var paramParts = sURLVariables[i].split('=');
var sParameterName = paramParts[0];
// first time we've seen it - add a blank array
if(!paramGroups.hasOwnProperty(sParameterName))
{
paramGroups[sParameterName] = [];
}
// ad to the array
if(paramParts.length > 1)
{
paramGroups[sParameterName].push(paramParts[1]);
}
else
{
// handle not having an equals (eg y in x=1&y&z=2)
paramGroups[sParameterName].push('');
}
}
return paramGroups;
}
// gets which indices of the specified parameter have a value set
function getSetUrlParameters(sParameterName)
{
var arr = getUrlParameterGroups()[sParameterName];
return arr.reduce(function(previousValue, currentValue, index) {
if(currentValue != '') {
previousValue.push(index);
}
return previousValue;
}, []);
}
var result = getSetUrlParameters('feature_filters[]');
console.log(result);