I have an array of objects that looks like this:
var data = [
{
title: 'Shirt',
position: 3
},
{
title: 'Ball',
position: 1,
}
]
How could I sort it for use in a for loop
like this.
for(var i in data) {
}
I tried:
for(var i in data | orderBy:'position')
But that is angular so normal Javascript it doesn't work.
I'm thinking their must be some way to sort the array before looping through it, or adding a filter to the loop, not sure which is the best way.