【问题标题】:put an element always on bottom while sorting排序时始终将元素放在底部
【发布时间】:2014-03-14 23:14:56
【问题描述】:

我有一个包含整数属性的项目列表(例如 div),它可以帮助我对该列表进行排序(升序和降序);无论排序标准如何,我都希望某些项目始终位于底部,有没有办法在这个整数属性上设置一个值来获得这个(另外,我在 desc 顺序中放置 -9999,在 asc 顺序中放置 999999,但我只需要一个值)。

【问题讨论】:

  • 从数组中删除,对数组进行排序,再添加回数组。
  • 你看到我的回答了吗?

标签: javascript html sorting


【解决方案1】:

这里是:

myArray = ['item1', 'item2', 'item3', 'itemLast', 'item4']; 

//SORT array here

// remove the item you want by name
myArray.splice(myArray.indexOf('itemLast'),1);

// push it again
myArray.push('itemLast');

【讨论】:

    猜你喜欢
    • 2011-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    相关资源
    最近更新 更多