fixed the page order problem, the first page will be selected.

Always check the data pass into the function, like check if it is an
array before using length property for that parameter.