For循环不执行数组中的最后一个函数(JavaScript)

For循环不执行数组中的最后一个函数(JavaScript),javascript,arrays,Javascript,Arrays,未执行boxFill()数组中的最后一个函数。我尝试计算数组的长度,但没有成功。(我对js很陌生,只是说)。它遍历前四个索引,并且始终不执行最后一个索引,即使我更改了索引的位置 var pResult1 = document.getElementById("result1"); var pResult2 = document.getElementById("result2"); var pResult3 = document.getElementById("result3"); var p

未执行boxFill()数组中的最后一个函数。我尝试计算数组的长度,但没有成功。(我对js很陌生,只是说)。它遍历前四个索引,并且始终不执行最后一个索引,即使我更改了索引的位置

var pResult1 = document.getElementById("result1");
 var pResult2 = document.getElementById("result2");
 var pResult3 = document.getElementById("result3");
 var pResult4 = document.getElementById("result4");
 var pResult5 = document.getElementById("result5");
 var pResult = [pResult1,pResult2,pResult3,pResult4,pResult5]

 function checkBox() {
    /*var aFlor = [2.8,"Florida","Science"];   
    var bGeo = [3.5,"Georgia","Business"];
    var cTex = [2.3,"Texas","Health"];
    var dNew = [4.2,"NewYork","Law"];
    var eMic = [3.9,"Michigan","Humanities"];*/
    var boxValue = document.getElementById("searchBox").value;
    var boxFill = [
      function(){listBox('1','Florida state Scholarship','3.5','Florida','Applied Sciences')},
      function(){listBox('2','Great Achievers Scholarship','4.0','Texas','Health')},
      function(){listBox('3','Helpful Future Scholarship','3.0','Georgia','Business')},
      function(){listBox('4','Never Give Up Scholarship','2.0','Michigan','Humanities')},
      function(){listBox('5','Times Square Talent Scholarship','3.5','New York','Law')}
    ]

  if  (boxValue.includes("f")) {
       for (i=0;i<boxFill.length+1;i++) {
        boxFill[i]();
       }
function listBox(number,name,gpa,state,major) { 
    pResult[number].innerHTML = 
"<dl><dt>"+number+". "+name+"</dt><dd>- minimum GPA is: "+gpa+"</dd><dd>- You must live in "+state+"</dd><dd>- For the "+major+" major!</dd></dl>";
 }
var preslt1=document.getElementById(“result1”);
var preslt2=document.getElementById(“result2”);
var preslt3=document.getElementById(“结果3”);
var preslt4=document.getElementById(“结果4”);
var preslt5=document.getElementById(“结果5”);
变量pResult=[preslt1,preslt2,preslt3,preslt4,preslt5]
函数复选框(){
/*var aFlor=[2.8,“佛罗里达州”,“科学”];
var bGeo=[3.5,“格鲁吉亚”,“商业”];
var cTex=[2.3,“德克萨斯州”,“健康状况”];
var dNew=[4.2,“纽约”,“法律”];
变量eMic=[3.9,“密歇根”,“人文学科”]*/
var-boxValue=document.getElementById(“searchBox”).value;
变量boxFill=[
函数(){listBox('1','Florida state Scholarship','3.5','Florida','Applied Sciences'),
函数(){listBox('2','Great Achievers Scholarship','4.0','Texas','Health'),
函数(){listBox('3','Future Scholarship','3.0','Georgia','Business')},
函数(){listBox('4','Never Dest Scholarship','2.0','Michigan','Humanitics')},
函数(){listBox('5','TimesSquare人才奖学金','3.5','NewYork','Law'))
]
if(包括(“f”)){

对于(i=0;i
i
i
还有一些更简单的方法可以完成我认为您想要做的事情,使用一个对象数组和一个函数来输出数据,而不是使用5个函数手动对每个函数进行编号。
还有一些更简单的方法可以完成我认为您想要做的事情,使用一组对象和一个函数来输出数据,而不是5个函数并手动编号。或者调用
boxFill[i+1]()
(稍后执行-1位)。;-)或者调用
boxFill[i+1]()
(稍后执行-1位)。;-)
var boxFill = [
  function(){listBox(0,'Florida state Scholarship','3.5','Florida','Applied Sciences')},
  function(){listBox(1,'Great Achievers Scholarship','4.0','Texas','Health')},
  function(){listBox(2,'Helpful Future Scholarship','3.0','Georgia','Business')},
  function(){listBox(3,'Never Give Up Scholarship','2.0','Michigan','Humanities')},
  function(){listBox(4,'Times Square Talent Scholarship','3.5','New York','Law')}
]
pResult[number-1].innerHTML = ...;