为什么这个数组不打印?

时间:2016-05-20 14:23:44

标签: javascript arrays function

我的代码:

arr = [1,2,3,4,5,6]

function printArray(arr){
  arrAtr = "";
  for(count = 0; count < arr; count++){
    arrAtr += (String(arr[count]) + " ")
  }
  document.write(arrAtr);
}

printArray(arr)

这不打印数组。我期待:

1 2 3 4 5 6

1 个答案:

答案 0 :(得分:2)

您的代码中存在错误。

你必须替换

printArray(myArr)

printArray(arr);

AND替换

for(count = 0; count < arr; count++){

for(count = 0; count < arr.length; count++){
相关问题