我想知道是否有可能有一个像多维数组的对象? 我想要的是:
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);
输出: 无法将undefined转换为对象
答案 0 :(得分: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