Try this,
var book = app.activeBook, _content = [], overlap = []; for(var i =book.bookContents.length-1;i>=0;i--) { _content.push(book.bookContents[i].name + "\t" + (book.bookContents[i].documentPageRange.replace(/-[^-]+$/g,"")) + "\r"); if(book.bookContents[i].documentPageRange == book.bookContents[i-1].documentPageRange) { overlap.push(book.bookContents[i].name + "\t" +book.bookContents[i].documentPageRange + "\r" + book.bookContents[i-1].name + "\t" +book.bookContents[i-1].documentPageRange); } } if(overlap.length >0) { alert(overlap.reverse()) } _content.reverse(); var con = ""; for(var i =0;i<_content.length;i++) { con+=_content[i] + "\r"; } WriteToFile(con); function WriteToFile(text) { file = new File("~/Desktop/Book contents and page number.txt"); file.encoding = "UTF-8"; file.open("w"); file.write(text); file.close(); file.execute(); }
Regards,
Chinna