所以我试图将一个数组的长度作为字符串推送到另一个数组。 我的逻辑是……对于 javascript
if x = [1];
and y = [1];
我想在 for 循环中将 x.length + 1 插入 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));
};
这是逻辑错误还是语法错误?
最佳答案
你正在写 y.push.toString
尝试:
for (i=0; i < 100; i++) {
var x = [1];
var y = [1];
y.push(x.length + 1)
document.writeln(y);
};
但我想你的意思是JSBIN Demo :
var y = [];
for (i=0; i < 100; i++) {
y.push(y.length + 1)
document.writeln(y + '<br/>');
};
关于javascript - 具有逻辑或语法问题的 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17873338/