数组对象排序在Javascript中不适用于大长度数据?

数组对象排序在Javascript中不适用于大长度数据?,javascript,arrays,sorting,Javascript,Arrays,Sorting,今天我遇到了一个问题,我不认为这个问题是因为Javascript中的代码或bug。我尝试对对象数组进行排序,如下所示 const array = [{ text:'one' count:5 }, { text:'two' count:5 }, { text:'three' count:5 }, { text:'four' count:5 }] 现在我需要根据计数索引对对象数组进行排序。我试过使用这些代码 Array.prototype.sortBy = function (p) {

今天我遇到了一个问题,我不认为这个问题是因为Javascript中的代码或bug。我尝试对对象数组进行排序,如下所示

const array = [{
text:'one'
count:5
},
{
text:'two'
count:5
},
{
text:'three'
count:5
},
{
text:'four'
count:5
}]
现在我需要根据计数索引对对象数组进行排序。我试过使用这些代码

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'))
Array.prototype.sortBy=函数(p){
返回此.slice(0).sort(函数(a,b){
返回(a[p]>b[p])?1:(a[p]

在这里,当对象数组长度小于100时,排序工作正常,但当对象数组长度大于100时,排序就不起作用。我也尝试了一些Npm软件包。但它不起作用。帮帮我吧

你把事情弄得太复杂了,你可以依靠
.sort
方法

显示它与500个元素一起工作,只是为了确保

const数组=[{
正文:“一”,
计数:3
}, {
正文:"两",,
计数:1
}, {
正文:"三",,
计数:2
}, {
正文:“四”,
计数:4
}];
让sorted=array.sort((a,b)=>a.count-b.count);
控制台日志(已排序)你所说的“行不通”到底是什么意思?你有错误吗?根本就没有分类吗?还是很糟糕?请具体一点,最好创建一个。它适合我,长度为200: