Don't use an array if you want named keys, use a plain object.
(如果要命名键,请不要使用数组,而应使用普通对象。)
var a = {};
a["key1"] = "value1";
a["key2"] = "value2";
Then:
(然后:)
if ("key1" in a) {
// something
} else {
// something else
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…