Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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 如何分配命名数组?_Javascript_Arrays - Fatal编程技术网

Javascript 如何分配命名数组?

Javascript 如何分配命名数组?,javascript,arrays,Javascript,Arrays,如果这是个愚蠢的问题,请原谅,我还是个初学者。以下是练习: function exerciseOne(classmates){ // Exercise One: You will be given an array called 'classmates' // Create a variable called 'howManyStudents', and assign it to // the length of the classmates array (using

如果这是个愚蠢的问题,请原谅,我还是个初学者。以下是练习:

function exerciseOne(classmates){    
// Exercise One: You will be given an array called 'classmates'    
// Create a variable called 'howManyStudents', and assign it to     
// the length of the classmates array (using the length property)
我的回答是:

let howManyStudents = classmates;
console.log(classmates.length);
当我试着运行测试时,它说预期答案['a','b','c','d','e']为5。如果它是['a'、'b'、'c'、'd'、'e'],我会很好,但它作为名称而不是数组的书写方式让我有点困惑

如果有人能告诉我我做错了什么,我会非常感激


编辑:成功了,非常感谢

您需要为变量指定classes.length属性

function exerciseOne(classmates){
 let howManyStudents = classmates.length;
 console.log(howManyStudents);

 return howManyStudents
}

您没有将同学的长度指定给howManyStudents变量,而是将同学的数据指定给howManyStudents,而不是指定同学的长度

应该是:

let howManyStudents = classmates.length;
console.log(howManyStudents);