Yes, .reverse() method helped:
var mStory = app.selection[0].insertionPoints[0].parentStory;
var aEndList = []; // prepare array
mFind ="\\{\\{\\{.+?\\}\\}\\}"; // my coding of text being searched (kinda {{{some needed text}}})
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findChangeGrepOptions.includeFootnotes = false;
app.findGrepPreferences.findWhat = mFind;
var mFound = mStory.findGrep();
$.writeln(mFound.length);
for (i = mFound.length-1; i>=0; i--){
mSel = mFound[i];
mStr_tmp = String(i+1) + ". " + mFound[i].contents; //temporary string with added number
mSel.select();
app.selection[0].remove();
//place number of refer instead of refer itself in text
mSel.insertionPoints[0].texts[0].position = Position.SUPERSCRIPT;
mSel.insertionPoints[0].texts[0].contents = String(i+1);
aEndList.push(mStr_tmp);
}
aEndList.reverse();
myString = aEndList.join ("\r");
//place resorted and numbered list
mStory.insertionPoints.item(-1).select();
mStory.insertionPoints.item(-1).contents = myString;
But the problem arose. Operating with contents looses text formatting. So i used cut-paste method. can i keep formattin by some way in this code?