JSFiddle - React, Tailwind, and code Playground
JavaScript
var objs = [
{
views: '17'
},
{
views: '6'
},
{
views: '2'
}
];
function sortByProperty(property) {
return function (a,b) {
return (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
}
}
objs.sort(sortByProperty('views'));
console.log(objs);