Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带有逻辑或语法问题的for循环_Javascript_For Loop_Syntax_Logic - Fatal编程技术网

Javascript 带有逻辑或语法问题的for循环

Javascript 带有逻辑或语法问题的for循环,javascript,for-loop,syntax,logic,Javascript,For Loop,Syntax,Logic,所以我尝试将数组的长度作为字符串推到另一个数组上。 我的逻辑是。。。对于javascript if x = [1]; and y = [1]; 我想把x.length+1推到for循环中的y数组,这样它就变成了 1. 12 123 1234 这就是我试图去做的,但是得到了一个阅读的结果 function push() { [native code] } function push() { [native code] } function push() { [native code]

所以我尝试将数组的长度作为字符串推到另一个数组上。 我的逻辑是。。。对于javascript

if    x = [1];
and   y = [1];
我想把x.length+1推到for循环中的y数组,这样它就变成了 1. 12 123 1234

这就是我试图去做的,但是得到了一个阅读的结果

function push() { [native code] } function push() { [native code] } function push() { [native code] } function push() { [native code] }
这是我的密码

for (i=0; i < 100; i++) {

        var x = [1];
        var y = [1];

            document.writeln(y.push.toString(x.length + 1));

    };
(i=0;i<100;i++)的
{
var x=[1];
变量y=[1];
document.writeln(y.push.toString(x.length+1));
};

这是逻辑错误还是语法错误?

您正在编写y.push.toString

尝试:

(i=0;i<100;i++)的
{
var x=[1];
变量y=[1];
y、 推动(x长度+1)
书面文件(y);
};
但我想你的意思是:

var y=[];
对于(i=0;i<100;i++){
y、 推动(y.长度+1)
文件写入(y+“
”); };
您正在编写y.push.toString

尝试:

(i=0;i<100;i++)的
{
var x=[1];
变量y=[1];
y、 推动(x长度+1)
书面文件(y);
};
但我想你的意思是:

var y=[];
对于(i=0;i<100;i++){
y、 推动(y.长度+1)
文件写入(y+“
”); };
也许您正在尝试这样做

    var x = [1];
    var y = [1];
for (i=0; i < 100; i++) {
       document.writeln(y.push(x.length + 1));
};
var x=[1];
变量y=[1];
对于(i=0;i<100;i++){
文件写入(y.push(x.length+1));
};

var x=[1];
变量y=[1];
对于(i=0;i<100;i++){
y、 推动(y.长度+1)
书面文件(y);
}

var y=“”
对于(i=1;i<100;i++){
y+=i
书面文件(y);
}

也许您正在尝试这样做

    var x = [1];
    var y = [1];
for (i=0; i < 100; i++) {
       document.writeln(y.push(x.length + 1));
};
var x=[1];
变量y=[1];
对于(i=0;i<100;i++){
文件写入(y.push(x.length+1));
};

var x=[1];
变量y=[1];
对于(i=0;i<100;i++){
y、 推动(y.长度+1)
书面文件(y);
}

var y=“”
对于(i=1;i<100;i++){
y+=i
书面文件(y);
}

这肯定是您想要的:

var y = [1];
for (i = 0; i < 10; i++) {
    var x = y[y.length-1].toString() + (y.length + 1);
    y.push(x);
} 
document.writeln(y.toString());
var y=[1];
对于(i=0;i<10;i++){
变量x=y[y.length-1].toString()+(y.length+1);
y、 推(x);
} 
document.writeln(y.toString());

这肯定是您想要的:

var y = [1];
for (i = 0; i < 10; i++) {
    var x = y[y.length-1].toString() + (y.length + 1);
    y.push(x);
} 
document.writeln(y.toString());
var y=[1];
对于(i=0;i<10;i++){
变量x=y[y.length-1].toString()+(y.length+1);
y、 推(x);
} 
document.writeln(y.toString());
我是这样得到它的

var y = [1];
    document.writeln(y + '<br>');
for (i=2; i < 101; i++) {
    y.push(i);
    document.writeln(y + '<br>' );
};
var y=[1];
document.writeln(y+“
”); 对于(i=2;i<101;i++){ y、 推(i); document.writeln(y+“
”); };
我是这样得到它的

var y = [1];
    document.writeln(y + '<br>');
for (i=2; i < 101; i++) {
    y.push(i);
    document.writeln(y + '<br>' );
};
var y=[1];
document.writeln(y+“
”); 对于(i=2;i<101;i++){ y、 推(i); document.writeln(y+“
”); };
你期望
y.push.toString
做什么?你期望
y.push.toString
做什么?我喜欢它,这就是我想要做的。我还想出了另一种方法,在每个数字之间加一个逗号。下面是我的答案。我不认为你可以在这上面加一个停顿,让每个数字都在自己的行上。我喜欢它,这就是我想做的。我还想出了另一种方法,在每个数字之间加一个逗号。下面是我的答案,我不认为你可以给这个问题增加一个中断,让每个数字都在自己的行上,这很像我最终发现的,这很像我最终发现的,最后一个打得很完美,最后一个是我会怎么做……)最后一个打得很完美最后一个是我会怎么做…)
var y = [1];
    document.writeln(y + '<br>');
for (i=2; i < 101; i++) {
    y.push(i);
    document.writeln(y + '<br>' );
};