2015-04-16 126 views
0

我正在研究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++)...,并且在运行时不再显示值。看看这些文档,我没有看到脚本无法正常工作的原因。我错过了明显的东西吗?

+0

回答

0

你需要得到音符的长度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; 
     } 
    }