我正在尝试创建一个多维的关联数组。我尝试了类似PHP的语法,但是它不起作用。怎么解决?

var var_s = ["books", "films"];
var_s["books"]["book1"] = "good";
var_s["books"]["book2"] = "bad";
var_s["films"]["films1"] = "bad";
var_s["films"]["films2"] = "bad";

最佳答案

使用对象:

var var_s = {"books":{}, "films": {}};
var_s["books"]["book1"] = "good";
-> {books: {book1: "good"}, films: {}}

10-04 10:39