Here is the code and fiddle:
var config = function(){
return {
name: ["john", "lucy", "lily"],
age: ["22", "21", "22"],
gender: ["male", "female", "female"],
people: function(index){
index--;
this.name = name[index];
this.age = age[index];
this.gender = gender[index];
},
people2: function(index){
index--;
this["name"] = name[index];
this["age"] = age[index];
this["gender"] = gender[index];
},
};
}();
alert(config.people(1).name);
alert(config.people2(1).name);
I can get the value by code like:
config.name[1];
I want to restructure a key/value array like:
{name:"john",age:22,gender:male}
The index value delegates the first, second and third people info. Can anyone help me to get the code working? I'm stuck!