这是我的代码的简单摘要:
var list = {
"group":{
"subgroup1":[{"name1":"Jimmy","name2":"Bob"}],
"subgroup2":[{"name1":"Sarah","name2":"Nick"},{"name1":"Kevin","name2":"George"}]
}
}
function group(group,name){
var linktothegroup;
//Note: In my actual code it will attempt to join a group before creating one this just creates a new one
//group: Specifies which subgroup to join (my actual code will check if it's valid this is just a simpler version
//name: the users name
list["group"][group].push({"name1":name,"name2":""});
linktothegroup = someway to link that group I just added; //I figured I could find the array slot and specify but that will change if a group is deleted
this.leavegroup = function(){
//leaves the group
//uses the linktothegroup var to be removed from the group
}
this.changename = function(name){
linktothegroup.name1 = name;
return true;
}
}
var cubscouts = new group("subgroup1","Billy");
cubscouts.changename("Fred");
我只想能够编辑“subgroupX”字段中的值(基本上用于changename函数),但是总是有组离开和加入,所以我不能在变量中指定数组槽。
所以基本上有没有办法编辑一个变量并改变另一个变量?