当前位置:网站首页>数组按指定顺序排序
数组按指定顺序排序
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);
});这样就可以了。
边栏推荐
- The R language uses the pyramid function of epidisplay package to visualize the pyramid graph and the pyramid graph based on the existing summary data (table data)
- Unprecedented analysis of Milvus source code architecture
- LCD参数解释及计算
- 布局管理中的sizePolicy的策略问题
- New media operation material website sharing enables you to create current affairs with half the effort
- Add static route
- Some minor problems and solutions encountered when using ubantu
- R language uses ggplot2 to visualize the density graph (curve) of specific data columns in dataframe data, and uses Xlim parameter to specify the range of X axis
- Yyds dry goods inventory leetcode question set 911 - 920
- Volcano engine held a video cloud technology force summit and released a new experience oriented video cloud product matrix
猜你喜欢

Microsoft Office MSDT Code Execution Vulnerability (cve-2022-30190) vulnerability recurrence

快速入门scrapy爬虫框架

Uniapp wallpaper applet source code / double ended wechat Tiktok applet source code

Atlas conflict Remote Code Execution Vulnerability (cve-2022-26134) vulnerability recurrence

5、Embedding

Nebula's practice of intelligent risk control in akulaku: training and deployment of graph model

I heard that distributed IDS cannot be incremented globally?

文章名字

龙芯处理器内核中断讲解

Detailed explanation of shardingjdbc database and table
随机推荐
R语言使用epiDisplay包的tableStack函数基于分组变量生成统计分析表(包含描述性统计分析、假设检验、不同数据使用不同的统计量和假设检验方法)、自定义配置是否显示统计检验内容
Gerrit+2 triggers Jenkins task
R language uses the sum function of epidisplay package to calculate the descriptive statistical summary information of the specified variables in dataframe under different grouped variables and visual
一物一码追踪溯源系统介绍
Microsoft Office MSDT代码执行漏洞(CVE-2022-30190)漏洞复现
反馈式编译
1723. minimum time to complete all work
The R language uses the tablestack function of epidisplay package to generate statistical analysis tables based on grouped variables (including descriptive statistical analysis, hypothesis test, diffe
Quick start sweep crawler framework
Li Kou today's question 926 Flip string to monotonic increment
406. 根据身高重建队列
qemu+gdb小节
Introduction to several common functions of fiddler packet capturing (stop packet capturing, clear session window contents, filter requests, decode, set breakpoints...)
记录使用yolov5进行旋转目标的检测
有趣的 LD_PRELOAD
Detailed explanation of shardingjdbc database and table
The R language uses the plot function to visualize the data scatter chart, and uses font The axis parameter specifies that the font type of the axis scale label is italic
php 实现无限极分类树(递归及其优化)
AlibabaProtect.exe如何删除、卸载
龙芯处理器内核中断讲解