【发布时间】:2014-02-18 11:29:11
【问题描述】:
我想要在 Javascript 中类似以下内容
如果 str.charAt(index) (在集合中) {".", ",", "#", "$", ";", ":"}
是的,我知道这一定很简单,但我似乎无法正确使用语法。我现在拥有的是
theChar = str.charAt(i);
if ((theChar === '.') || (theChar === ',') || (theChar === ... )) {
// do stuff
}
这可行,但必须有更好的方法。
编辑:我这样做了,但不确定它是否好:
var punc = {
".":true,
",":true,
";":true,
":":true
};
if (punc[str.charAt[index]) { ...
【问题讨论】:
标签: javascript charat