Question: I have this string which I want to convert to an array:

```
var test = "{href:'one'},{href:'two'}";

```

So how can I convert this to an array?:

```
var new = [{href:'one'},{href:'two'}];

```

Answer: 
It depends where you got it from..

If possible you should correct it a bit to make it valid JSON syntax (*at least in terms of the quotes*)

```
var test  = '{"href":"one"},{"href":"two"}';
var arr = JSON.parse('[' + test + ']');

```

Notice the `"` around both keys and values.

(*making directly `var test = '[{"href":"one"},{"href":"two"}]';` is even better*)
If changing the string to be valid JSON is not an option, **and you fully trust this string, and its origin** then I would use eval:

```
var test = "{href:'one'},{href:'two'}";
var arr = eval("[" + test + "]");

```

On that last note, please be aware that, if this string is coming from the user, it would be possible for them to pass in malicious code that `eval` will happily execute.

As an extremely trivial example, consider this

```
var test = "(function(){ window.jQuery = undefined; })()";
var arr = eval("[" + test + "]");

```

Bam, jQuery is wiped out. 

Demonstrated [here](http://jsfiddle.net/J3SaH/)