无法通过循环将字符串存储到另一个变量中

时间:2018-05-13 22:33:39

标签: javascript string

for (var j=0, new1=""; j<fs.length; j++) {
    new1[j] = fs[j];
    console.log(new1[j]);
    console.log(fs[j]);
}

console.log(fs[j]) // is displaying the value contained in fs.

console.log(new1[j]) // is displaying "undefined" only.

为什么变量fs在给new1的值时很害羞?

1 个答案:

答案 0 :(得分:1)

我没有使用字符串,而是使用了数组并对其进行了整理。我已经使用push()方法创建了一个数组并在其中添加了字符。 new1.push(FS [J]);