In my current code, I am extracting the value of an input name array key using JavaScript:
var input = document.querySelector('input');
var value = input.name.match(/\[(.*?)\]/)[1];
console.log(value);
<input type="text" name="hello[101][]" />
This method is effective, but I'm interested in exploring alternative approaches to retrieve the input name array key value(s)
. Is there a way to transform the string hello[101][]
into a JavaScript array or object? For example, how can I extract all keys from:
<input type="text" name="hello['one'][101]['test'][]" />