无法让 for 循环正确打印

Can't get for loop to print correctly

我正在开发一个 Google 脚本来从文档中的脚注创建尾注。除了在删除脚注后替换上标外,一切正常。具体来说,我无法让 for 循环从 1 而不是零开始计数。

脚本位是:

function replaceNotes() {
  var par = body.getParagraphs();
  var notes = DocumentApp.getActiveDocument().getFootnotes();

  for(var i in notes){
    notes[i].getParent().editAsText().appendText(i);
    return;
  }
}

这有效,但它从 0 开始打印,这是预期的。因此,我将循环设置为 for(var i = 1; i < notes; i++)...,当 运行 时它不再打印值。查看文档,我看不出脚本无法运行的任何原因。我是否漏掉了一些明显的东西?

您需要使用 notes.length

获取音符的长度
  function replaceNotes() {
      var par = body.getParagraphs();
      var notes = DocumentApp.getActiveDocument().getFootnotes();

      for(var i = i; i < notes.length; i++){
        notes[i].getParent().editAsText().appendText(i);
        return;
      }
    }