How can I order by key as integer?
I have the following Object;
$scope.data = {
\"0\": { data: \"ZERO\" },
\"1\": { data: \"ONE\" },
\"2
app.filter('orderObjectBy', [function() {
return (filterObj, prop) => {
let arr = []
//below is the loadash function you can use for in also
_.forEach(filterObj, function(value, key) {
arr.push({
key: key,
value: value
});
});
let sortedArr = _.sortBy(arr, val => val.value[prop]);
for (let variableKey in filterObj) {
if (filterObj.hasOwnProperty(variableKey)) {
delete filterObj[variableKey];
}
}
for (let data of sortedArr) {
filterObj[data.key] = data.value;
}
return filterObj;
}
}])