0

我想知道是否有可能拥有像多维数组这样的对象?我想要的是这样的:

lines[first][first first]= "value key key"        


    lines          =       {};
    key            =       "first";
    key_key        =       "first first";
    lines[key]     =       "value key ";
    lines[key][key_key]=   "value key key "

    console.log(lines);

输出:无法将未定义转换为对象

4

1 回答 1

1

lines[key]是一个字符串值。它应该是一个对象。像这样:

lines              = {};
key                = "first";
key_key            = "first first";
lines[key]         = {};
lines[key][key_key]= "value key key ";
//=> lines.first['first first'] now is 'value key key'

或者

lines              = {};
key                = "first";
key_key            = "first first";
lines[key]         = new String("value key ");
lines[key][key_key]= "value key key ";
//=> lines.first['first first'] still is 'value key key', 
//   but now it's a custom property of a String Object
于 2012-06-01T15:36:56.897 回答