[英]For loop with array elements Inside function. How to return the function output?
How can i get the output of these below two for loop's console.log via function call.我如何通过 function 调用获得以下两个 for 循环的 console.log 的 output 。 Code snippet given below.
下面给出的代码片段。
CODE BELOW:下面的代码:
var scoreDolphins = [96, 108, 89]; var scoreKolas = [88, 91, 110]; var avgD_Div = scoreDolphins.length; console.log(avgD_Div); var avgK_Div = scoreKolas.length; console.log(avgK_Div); var calcAvgF = function() { for (let scoreItem_D = 0; scoreItem_D < scoreDolphins.length; scoreItem_D++) { console.log(scoreDolphins[scoreItem_D]); } console.log("---------------------------------------------------------------------------"); for (let socreItem_K = 0; socreItem_K < scoreKolas.length; socreItem_K++) { console.log(scoreKolas[socreItem_K]); } return calcAvgF; } console.log(calcAvgF);
calcAvgF
should not return calcAvgF
iteslf. calcAvgF
不应返回calcAvgF
itemslf。 Also you should call calcAvgF
function unstead of console.log(calcAvgF)
你也应该调用
calcAvgF
function 而不是console.log(calcAvgF)
var scoreDolphins = [96, 108, 89]; var scoreKolas = [88, 91, 110]; var avgD_Div = scoreDolphins.length; var avgK_Div = scoreKolas.length; var calcAvgF = function () { for (let scoreItem_D = 0; scoreItem_D < scoreDolphins.length; scoreItem_D++) { console.log(scoreDolphins[scoreItem_D]); } for (let socreItem_K = 0; socreItem_K < scoreKolas.length; socreItem_K++) { console.log(scoreKolas[socreItem_K]); } } calcAvgF();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.