Javascript 丢失的 ; 在 for 循环初始化程序之后
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5718068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
missing ; after for-loop initializer
提问by vissu
var nodeWordsString = document.getElementById("nodeWordsTextArea").value.trim();
var nodeWordsStringArray=nodeWordsString.split(" ");
var strLength = nodeWordsStringArray.length;
for(int i = 0; i < nodeWordsStringArray.length; i++)----->******
{
for(int j = 0; j < nodeWordsStringArray.length; j++)
{
if(nodeWordsStringArray(i) == nodeWordsStringArray(j))
{
alert("Node duplication occurred at:"+nodeWordsStringArray(i));
return false;
//break;
}
}
}
**showing error like missing ; after for-loop initializer
in java script console(firebug).
please help me.
**显示错误,如missing ; after for-loop initializer
java脚本控制台(firebug)。请帮我。
回答by Brad Christie
This is javascript, but you're using int
in your loop declaration? Try replacing those with var
instead.
这是javascript,但您int
在循环声明中使用?尝试将它们var
替换为。
回答by Rocket Hazmat
Change int i
and int j
to var i
and var j
.
变化int i
和int j
以var i
和var j
。
回答by Limon Monte
In my case, the error was caused by using let
in the loop. Old browsers like Firefox 38 doesn't support let
.
就我而言,错误是由let
在循环中使用引起的。Firefox 38 等旧浏览器不支持let
.
Replacing let
by var
solved the issue.
let
通过替换var
解决了问题。
回答by lpd
If you are here in 2016, maybe you are trying to use a let
declaration outside strict mode in a browser that does not yet support it. Replace it with var
or add 'use strict;'
to the top of your function.
如果您在 2016 年在这里,也许您正试图let
在尚不支持严格模式的浏览器中使用严格模式之外的声明。将其替换为var
或添加'use strict;'
到函数的顶部。
回答by Raynos
var strLength = nodeWordsStringArray.length;
for(int i = 0; i < nodeWordsStringArray.length; i++)
You can use for (int i = 0; i < strLength; i++)
it is more efficient. As for your actual error try moving your brackets to the end of your for line. for(..;..;..) {
你可以使用for (int i = 0; i < strLength; i++)
它更有效率。至于您的实际错误,请尝试将括号移到 for 行的末尾。for(..;..;..) {
P.S. as mentioned there is no int
.
PS如上所述没有int
。