I am working with an array that looks like this:
[Object,Object,Object];
Each object in the array has a property named "rate". I need to sort these objects based on their rate property.
In my JavaScript, I have a variable called $scope.restaurants.data
, and here is its structure:
Array[3]
0:Object
ID:3
name:"bestRest"
profile:"rest.png"
rate:1
restaurantCitySlug:"NY"
slug:"foo"
__proto__:Object
1:Object
ID:7
name:"bestRes3t"
profile:"rest7.png"
rate:0
restaurantCitySlug:"NY"
slug:"fo4o"
__proto__:Object
2:Object
ID:7
name:"bestR242es3t"
profile:"re3st7.png"
rate:2
restaurantCitySlug:"NY"
slug:"fo244o"
__proto__:Object
My expectation after sorting is:
Array[3]
0:Object
ID:7
name:"bestRes3t"
profile:"rest7.png"
rate:0
restaurantCitySlug:"NY"
slug:"fo4o"
__proto__:Object
1:Object
ID:3
name:"bestRest"
profile:"rest.png"
rate:1
restaurantCitySlug:"NY"
slug:"foo"
__proto__:Object
2:Object
ID:7
name:"bestR242es3t"
profile:"re3st7.png"
rate:2
restaurantCitySlug:"NY"
slug:"fo244o"
__proto__:Object