Question: I have tag like this, how the best way to get every key and value of those attribute and populate it within an array (number of attribute will be increasing)?

```
myData = '[data attr1="value1" attr2="value2" attr3="value3"]';

```

and get result array :

```
var arr = new Array();
arr['attr1'] = "value1";
arr['attr2'] = "value2";
arr['attr3'] = "value3";
and so on...

```

Answer: 
This probably does what you want, though it assumes that `tag` is already in the format you have described, i.e. a singular occurrence of `[data ... ]`.

Also, the regular expression is purely based on what I've seen in your question; not sure whether it will break on other strings.

```
function decode(tag)
{
    var r = /(\w+)="([^"]*)"/g,
    h = {};
    while ((m = r.exec(tag)) !== null) {
        h[m[1]] = m[2];
    }
    return h;
}

```
Since you have string key in the data, use jquery object instead of array.

```
var arr = {};
var str = '[data attr1="value1" attr2="value2" attr3="value3"]​​​';
var n = str.split('[data ');
var str_arr = n[1].replace(']','').split(" ");
jQuery.each(str_arr,function(val){
    var x = str_arr[val].split('=');
    arr[x[0]]  = x[1].replace('"','').slice(0,-1);

});
console.log(arr);

```

Try this code. It may help you.

Here is the [DEMO](http://jsfiddle.net/EXPwR/)

Though it can be more optimized if you put some more details about your code.