[英]How can I display my array from this line of code?
<!DOCTYPE html>
<html>
<body>
<script>
var a = 33;
var b = 6;
var famList = [a, b];
function famDisp (){
for (var i=0, num=famList.length; i<num; i++){
famList[i];
}
}
famDisp(famList);
</script>
</body>
</html>
I would like to display the array famList but I am not getting any result.我想显示数组 famList 但我没有得到任何结果。 Using console.log to display I get this error "Uncaught TypeError: famList is undefined" What have I been doing wrong?
使用 console.log 显示我收到此错误“Uncaught TypeError: famList is undefined”我做错了什么?
I think you missed parameter in famDisp () so replaced我想你错过了famDisp() 中的参数所以替换了
famDisp ()
TO到
famDisp (famList)
then it will be work perfectly然后它会完美地工作
var a = 33; var b = 6; var famList = [a, b]; function famDisp (famList){ for (var i=0, num=famList.length; i<num; i++){ famList[i]; console.log(famList[i]) } } famDisp(famList);
<!DOCTYPE html> <html> <body> Html code </body> </html>
If your question is where to write the console.log just write it wherever you wanted it to be in the script tag.如果您的问题是在哪里编写 console.log,只需将它写在您希望它在脚本标记中的任何位置。 but if you want to display the values in the browser window then the concept if "document.getlementby'id , class name or tagnmae '" should be applied.
但是如果你想在浏览器窗口中显示值,那么应该应用“document.getlementby'id, class name or tagnmae '”的概念。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1 id="ht-tag">display the result here </h1>
<script>
var a = 33;
var b = 6;
var famList = [a, b];
let num = famList.length
function famDisp() {
for (var i = 0; i < num; i++) {
famList[i];
console.log(famList[i])
text = document.createTextNode(famList[i] + " ,")
document.getElementById("ht-tag").appendChild(text)
}
}
famDisp(famList);
</script>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.