当前位置:网站首页>Array sorts in the specified order
Array sorts in the specified order
2022-06-12 17:40:00 【Deshun】
Array sorting can be used directly sort()
Method , You can sort arrays regularly .
But if you specify an irregular order for sorting ?
It can also be used sort()
Method :
const data = [
{ name: ' Zhang San ', code: 'zs' },
{ name: ' Wang Wu ', code: 'ww' },
{ name: ' Zhao Qi ', code: 'zq' },
];
data.sort((star, next) => {
const sortList = ['zq', 'zs', 'ww']
return sortList.indexOf(star.code) - sortList.indexOf(next.code);
});
That's it .
No reprint without permission :w3h5 » Array sorts in the specified order
边栏推荐
- Microsoft Office MSDT Code Execution Vulnerability (cve-2022-30190) vulnerability recurrence
- Gerrit triggers Jenkins sonarqube scan
- Use of split method of string
- Guitar Pro tutorial how to set up a MIDI keyboard
- R语言使用pdf函数将可视化图像结果保存到pdf文件中、使用pdf函数打开图像设备、使用dev.off函数关闭图像设备、自定义width参数和height参数指定图像的宽度和高度
- Introduction to several common functions of fiddler packet capturing (stop packet capturing, clear session window contents, filter requests, decode, set breakpoints...)
- String s = null ; String s = new String();String s =““ ;String s ;有什么区别?
- 山东大学软件学院项目实训-创新实训-山大软院网络攻防靶场实验平台(二十五)-项目个人总结
- 二分查找的理解
- Tensorflow reads data from the network
猜你喜欢
Evolution and thinking of Taobao native R & D mode | DX R & D mode
Goframe gredis configuration management | comparison of configuration files and configuration methods
Arm64栈回溯
Cesium抛物线方程
Arm64 stack backtracking
Quick start sweep crawler framework
Exclusive interview with oppo find X5 Product Manager: deeply cultivate self-developed chips to create the ultimate flagship experience with the highest standards
Installation and use of rolabelimg
Deep interest evolution network for click through rate prediction
Hangzhou AI developer meetup registration opens!
随机推荐
Crazy temporary products: super low price, big scuffle and new hope
Arm64栈回溯
Exclusive interview with oppo find X5 Product Manager: deeply cultivate self-developed chips to create the ultimate flagship experience with the highest standards
Volcano engine held a video cloud technology force summit and released a new experience oriented video cloud product matrix
Go variables
Second week of electric control learning
Getting started with grpc swift
I heard that distributed IDS cannot be incremented globally?
Implementation of asynchronous query of Flink dimension table and troubleshooting
Sizepolicy policy in layout management
Analysis of CA certificate with high value
(4) Golang operator
Project training of Software College of Shandong University - Innovation Training - network attack and defense shooting range experimental platform of Software College of Shandong University (XXV) - p
JDBC几个坑
消息队列实战之队列优先级
淘宝Native研发模式的演进与思考 | DX研发模式
Tcp/ip family structure and protocol of tcp/ip series overview
WinForm, crystal report making
SqlServer常用语句及函数
卖疯了的临期产品:超低价、大混战与新希望