You can get around the whole problem by using a more complete object instead:
var objarr = [ {fname: "John", lname: "Smith", age: "23"}, {fname: "jerry", lname: "smith", age: "24"} ] ; objarr[0].fname; // = "John" objarr[1].age; // = "24"
Or if you really need an object:
var obj = { people: [ {fname: "John", lname: "Smith", age: "23"}, {fname: "jerry", lname: "smith", age: "24"} ]} ; obj.people[0].fname; // = "John" obj.people[1].age; // = "24"
Now, instead of using a regular expression, you can easily loop through an array by changing the index of the array:
for (var i=0; i<obj.people.length; i++) { var fname = obj.people[i].fname;
Blazemonger
source share