当前位置:首页 > 通信资讯 > 正文

javascript lastindexof(jquery lastindexof)

看下面这段代码:

  1. functiontest(s){
  2. varreg=/./g;
  3. console.log(reg.exec(s));
  4. console.log(reg.lastIndex);
  5. varreg=/./g;
  6. console.log(reg.exec(s));
  7. console.log(reg.lastIndex);
  8. }
  9. test("abcd");
  10. test("efgh");


我以为输出的lastIndex的值应该都是1,但是实际上的输出如下:
a
1
a
1
f
2
f
2
感觉就像是在第二次调用test的时候第2行和第6行并没有产生新的正则表达式,其之前的属性lastIndex还保留着(lastIndex=1)。这有点不合常理,头疼中。。。。。。

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。