当前位置:网站首页>数组按指定顺序排序
数组按指定顺序排序
2022-06-12 17:32:00 【德顺】
数组排序可以直接使用 sort() 方法,可以对数组按规律排序。
但如果指定一个没有规律的顺序进行排序呢?
同样可以使用 sort() 方法:
const data = [
{ name: '张三', code: 'zs' },
{ name: '王五', code: 'ww' },
{ name: '赵七', code: 'zq' },
];
data.sort((star, next) => {
const sortList = ['zq', 'zs', 'ww']
return sortList.indexOf(star.code) - sortList.indexOf(next.code);
});这样就可以了。
边栏推荐
- 迄今微软不同时期发布的SQL Server各版本之间的大致区别,供参考查阅
- How to use the official documents of pytorch and torchvision
- Learn the mitmproxy packet capturing tool from scratch
- 电控学习 第二周
- Tidb Hackathon 2021 - pcloud: conduct icloud pcloud team interview on the database
- 徽商期货公司开户可靠,交易安全吗?
- 邱盛昌:OPPO商业化数据体系建设实战
- MySQL提权总结
- Alibaba cloud image station supports IPv6!
- 如何查看、修改和删除SSH
猜你喜欢

I heard that distributed IDS cannot be incremented globally?

邱盛昌:OPPO商业化数据体系建设实战

Risc-v ide mounriver studio v1.60 update point introduction

Gerrit+2 triggers Jenkins task

1723. minimum time to complete all work

2080 virtual machine login command

迄今微软不同时期发布的SQL Server各版本之间的大致区别,供参考查阅

写技术博客的意义

WinForm, crystal report making

How to win the "Olympic Games" in retail technology for jd.com, the learning tyrant of the "regular examination"?
随机推荐
Go variables
Selenium element positioning
Arm64栈回溯
MySQL事务简介、事务隔离级别
Some introduction to FPC flexible circuit board design
How to use the official documents of pytorch and torchvision
Gerrit triggers Jenkins sonarqube scan
Figma from getting started to giving up
卖疯了的临期产品:超低价、大混战与新希望
selenium元素定位
Implementation of asynchronous query of Flink dimension table and troubleshooting
Yyds dry goods inventory leetcode question set 911 - 920
Tensorflow reads data from the network
快速入门scrapy爬虫框架
借助SpotBugs将程序错误扼杀在摇篮中
有趣的 LD_PRELOAD
How to win the "Olympic Games" in retail technology for jd.com, the learning tyrant of the "regular examination"?
(3) Golang - data type
Enterprise internal online training system source code
ShardingJDBC 分库分表详解