'Trouble accessing Footnotes class Google Scripts

I'm trying to write up a simple script which will take a footnote added to a Google Document and copy it into an endnotes section. So, the user would use footnotes as normal and then run the script to shift them to the end of the document when they're finished.

I've got a script which returns an array containing [Footnote, Footnote] from my test doc with two included, but I cannot figure out how to convert the object to a string.

function getNotes() {
  var doc = DocumentApp.getActiveDocument().getFootnotes();
  Logger.log(doc);
}

I've pored over the documentation, and I'm really confused because I can't seem to find the getFootnoteContents method mentioned in the Footnotes class. Any direction would be really appreciated.



Solution 1:[1]

getFootnotes() return an array of footnote objects. You will need to iterate over them to access each one.

function getFootnotes(){
  var doc = DocumentApp.openById('...');
  var footnotes = doc.getFootnotes();
  for(var i in footnotes ){
    Logger.log(footnotes[i].getFootnoteContents().getText());    
  }    
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Spencer Easton