Today I came across with one issue, I don't it this issue is coming because of code or bugs in Javascript. I tried to sort object array, which is like this
const array = [{
text:'one'
count:5
},
{
text:'two'
count:5
},
{
text:'three'
count:5
},
{
text:'four'
count:5
}]
Now I need to sort the object array based on the count index. I tried with these piece of code
Array.prototype.sortBy = function (p) {
return this.slice(0).sort(function (a, b) {
return (a[p] > b[p]) ? 1 : (a[p] < b[p]) ? -1 : 0;
});
}
console.log(array.sortBy('count'))
Here sorting is working fine when I have object array length as less than 100, but won't work when I have more than that length. I tried with some Npm packages also. But it doesn't work. Help me