所以我想要以后可以访问的多个值。这是我试过的:
function extraTime(input) {
var dayAndMonth = {
Oct: 'October',
Jul: 'July',
Aug: 'August',
Jun: 'July',
Apr: 'April',
Feb: 'February',
Mar: 'March',
Jan: 'January',
Thu: 'Thursday,',
Sat: 'Saturday,',
Wed: 'Wednesday,',
};
return dayAndMonth.input
}
例如,我的输入将为'Wed'
。我想回复'Wednesday'
作为回应。我之前见过这样的事情,但不确定我是否正确行事。我以为它被称为地图。
答案 0 :(得分:2)
您可以使用括号function extraTime(input) {
var dayAndMonth = {
Oct: 'October',
Jul: 'July',
Aug: 'August',
Jun: 'July',
Apr: 'April',
Feb: 'February',
Mar: 'March',
Jan: 'January',
Thu: 'Thursday,',
Sat: 'Saturday,',
Wed: 'Wednesday,',
};
return dayAndMonth[input];
}
console.log(extraTime('Mar'));
表示法:
[]
答案 1 :(得分:1)
您需要使用括号表示法来访问您的对象,例如
MongoClient mongo = new MongoClient();
DB db = mongo.getDB("pingax");
DBCollection coll = db.getCollection("aggregationExample");
/*
MONGO SHELL : db.aggregationExample.aggregate(
{$match : {type : "local"}} ,
{$project : { department : 1 , amount : 1 }}
);
*/
DBObject match = new BasicDBObject("$match", new BasicDBObject("type", "local"));
DBObject project = new BasicDBObject("$project", new BasicDBObject("department", 1).append("amount", 1));
AggregationOutput output = coll.aggregate(match,project,group,sort);
所以你的完整功能可能如下所示:
dayAndMonth['Wed']