@brian_p_dts -- You code returns the penultimate line of a text frame.
@Sayed Ali Mousawi Your code doesn't work because InDesign pages don't contain lines directly. They contain text frames, which in turn contain lines, as Brian's code shows. Another problem in your code would have been that
myRightPage.textFrames[0].lines.everyItem()
returns a collection, whereas .slice() is an array function. In addition, .slice() is a text function, and you want to target not text but InDesign text objects.
To target all lines in the text frame on a page but the last one, you need this:
var myRightPage_lines_except_last = myRightPage.textFrames[0].lines.itemByRange(0, -2);
This assumes that you have only one text frame.
P.