Created
May 31, 2017 15:30
-
-
Save hsuanxyz/39b68ab0a4282aaf3a56504e5b32ca33 to your computer and use it in GitHub Desktop.
code-view
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let items = [ | |
{id:4, config:null}, | |
{id:4, config:null}, | |
{id:1, config:'hello'}, | |
{id:2, config:'hello'}, | |
{id:7, config:null}, | |
{id:3, config:'hello'}, | |
] | |
// 定义安权重值排序的数组 | |
let sortIndex = [1, 3, 2, 4, 5, 7]; | |
// 去除 config 为 null 的项 | |
let sortItems = items.filter( e => e.config !== null); | |
// 根据权重索引排序 | |
sortItems.sort( (a,b) => sortIndex.indexOf(a.id) - sortIndex.indexOf(b.id)); | |
// 第一个就是符合条件的项 | |
console.log(sortItems[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment