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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:34:54  来源:igfitidea点击:

missing ; after for-loop initializer

javascript

提问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 initializerin java script console(firebug). please help me.

**显示错误,如missing ; after for-loop initializerjava脚本控制台(firebug)。请帮我。

回答by Brad Christie

This is javascript, but you're using intin your loop declaration? Try replacing those with varinstead.

这是javascript,但您int在循环声明中使用?尝试将它们var替换为。

回答by Rocket Hazmat

Change int iand int jto var iand var j.

变化int iint jvar ivar j

回答by Limon Monte

In my case, the error was caused by using letin the loop. Old browsers like Firefox 38 doesn't support let.

就我而言,错误是由let在循环中使用引起的。Firefox 38 等旧浏览器不支持let.

Replacing letby varsolved the issue.

let通过替换var解决了问题。

回答by lpd

If you are here in 2016, maybe you are trying to use a letdeclaration outside strict mode in a browser that does not yet support it. Replace it with varor 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