【发布时间】:2018-12-14 14:42:08
【问题描述】:
请考虑下面的 JavaScript 代码。
var obj = /e/.exec("The best things in life are free!");
var k = "";
var x;
for (x in obj) {
k = k + " " + obj[x] + " " + x + "<br>";
}
document.getElementById("demo").innerHTML = (obj instanceof Array) + " " + obj[0] + " " + obj[1] + " " + obj.index + "<br>" + k;
<h2>JavaScript Regular Expressions</h2>
<p id="demo"></p>
给出一个输出
JavaScript Regular Expressions
true e undefined 2
e 0
2 index
The best things in life are free! input
undefined groups
现在在上面的代码中,我使用了obj[0]obj[1](which are array only notations), and alsoobj.index`(它不应该适用于数组)。
现在我真的很困惑 obj 到底是什么......
【问题讨论】:
标签: javascript arrays regex