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: 
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.
```
var tagRe = /\[(\w+)((?:\s+\w+="[^"]{0,50}")*)\s*]/g;
var attrRe = /\b(\w+)="([^"]*)"/g;

function parse(text) {
    var result = [];
    tagRe.lastIndex = 0; // reset start position

    var tagMatch = tagRe.exec(text);
    while (tagMatch) {
        var currentTag = { 'name': tagMatch[1], 'attrs': {} };

        var attrString = tagMatch[2];
        attrRe.lastIndex = 0;

        var attrMatch = attrRe.exec(attrString);
        while (attrMatch) {
            var attrName = attrMatch[1];
            var attrValue = attrMatch[2];

            currentTag.attrs[attrName] = attrValue;

            attrMatch = attrRe.exec(attrString); // next match
        }
        result.push(currentTag);

        tagMatch = tagRe.exec(text);
    }
    return result;
}

parse('[data attr1="value1" attr2="value2" attr3="value3"]');
> [{name:'data',attrs:{attr1:'value1',attr2:'value2',attr3:'value3'}}]

```

This works for any number of tags in the string. The name of the tag does not matter.