【发布时间】:2012-01-07 04:09:56
【问题描述】:
给定一个包含字符串值的变量str,这两行代码是否等效?
A 行:
if ( [ 'foo', 'bar', 'baz' ].indexOf( str ) > -1 ) {
B 行:
if ( /^foo|bar|baz$/.test( str ) ) {
【问题讨论】:
-
不完全重复。他想将 indexOf 转换为正则表达式,该问题想在正则表达式上调用 indexOf。
标签: javascript regex theory