var obj = {
Fname1: \"John\",
Lname1: \"Smith\",
Age1: \"23\",
Fname2: \"Jerry\",
Lname2: \"Smith\",
Age2: \"24\"
}
with an object like this.
You can sidestep the entire 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 regex, you can easily loop through the array by varying the array index:
for (var i=0; i