Jafar Rasooli Jafar Rasooli - 3 months ago 27
Javascript Question

how can I reversely iterate on an aurelia array repeater?

I am trying to iterate from the end of an array to the beginning of it.

For example:


export class RepeaterTemplate {
constructor() {
this.friends = [


<p repeat.for.reverse ="friend of friends">Hello, ${friend}!</p>


Hello Dana
Hello Carol
Hello Bob
Hello Alice

Answer Source

As far as I know Aurelia doesn't have any explicit functions for this, but you could make a simple function in the viewmodel:

reverse(arr) {
    return arr.slice().reverse();

Then in the view:

   <p repeat.for="friend of reverse(friends)">Hello, ${friend}!</p>