当前位置:网站首页>Sort sort
Sort sort
2022-07-27 23:48:00 【yibucuo】
arr.sort() Don't pass parameters , When sorting Pure Strings
var arr = ['a', 'cc', 'ef', 'cb', 'ca', 'ea', 'bc']
arr.sort()
console.log(arr); // ['a', 'bc', 'ca', 'cb', 'cc', 'ea', 'ef']
brr.sort() Don't pass parameters , When excluding pure numbers
var brr = [10, 5, 2, 8, 1, 100, 30, 12, 4, 3]
brr.sort()
console.log(brr);// [1, 10, 100, 12, 2, 3, 30, 4, 5, 8]
crr.sort() Don't pass parameters , Mixed sorting of numbers and strings
var crr = ['a', 10, 'cc', 5, 'ef', 'cb', 2, 'ca', 8, 'ea', 1, 'bc', 100,'a1','c1', 30, 12, 4, 3]
crr.sort()
console.log(crr);// [1, 10, 100, 12, 2, 3, 30, 4, 5, 8, 'a', 'a1', 'bc', 'c1', 'ca', 'cb', 'cc', 'ea', 'ef']
drr.sort((a, b) => a - b)
var drr = [10, 5, 2, 8, 1, 100, 30, 12, 4, 3]
drr.sort((a, b) => a - b)
console.log(drr);// [1, 2, 3, 4, 5, 8, 10, 12, 30, 100]
err.sort((a, b) => a.first_name.localeCompare(b.first_name))
var err = [
{
first_name: 'a', last_name: 'a_a' },
{
first_name: 'cc', last_name: 'cc_cc' },
{
first_name: 'ef', last_name: 'ef_ef' },
{
first_name: 'cb', last_name: 'cb_cb' },
{
first_name: 'ca', last_name: 'ca_ca' },
{
first_name: 'ea', last_name: 'ea_ea' },
{
first_name: 'bc', last_name: 'bc_bc' },
];
err.sort((a, b) => a.first_name.localeCompare(b.first_name))
console.log(err);
[{
…}, {
…}, {
…}, {
…}, {
…}, {
…}, {
…}]
0: {
first_name: 'a', last_name: 'a_a'}
1: {
first_name: 'bc', last_name: 'bc_bc'}
2: {
first_name: 'ca', last_name: 'ca_ca'}
3: {
first_name: 'cb', last_name: 'cb_cb'}
4: {
first_name: 'cc', last_name: 'cc_cc'}
5: {
first_name: 'ea', last_name: 'ea_ea'}
6: {
first_name: 'ef', last_name: 'ef_ef'}
length: 7
The overall code is as follows :
<!DOCTYPE html>
<html lang="en">
<body>
<script> var arr = ['a', 'cc', 'ef', 'cb', 'ca', 'ea', 'bc'] arr.sort() console.log(arr); // ['a', 'bc', 'ca', 'cb', 'cc', 'ea', 'ef'] </script>
<script> var brr = [10, 5, 2, 8, 1, 100, 30, 12, 4, 3] brr.sort() console.log(brr);// [1, 10, 100, 12, 2, 3, 30, 4, 5, 8] </script>
<script> var crr = [10, 5, 2, 8, 1, 100, 30, 12, 4, 3] crr.sort((a, b) => a - b) console.log(crr);// [1, 2, 3, 4, 5, 8, 10, 12, 30, 100] </script>
<script> var drr = [ {
first_name: 'a', last_name: 'a_a' }, {
first_name: 'cc', last_name: 'cc_cc' }, {
first_name: 'ef', last_name: 'ef_ef' }, {
first_name: 'cb', last_name: 'cb_cb' }, {
first_name: 'ca', last_name: 'ca_ca' }, {
first_name: 'ea', last_name: 'ea_ea' }, {
first_name: 'bc', last_name: 'bc_bc' }, ]; drr.sort((a, b) => a.first_name.localeCompare(b.first_name)) console.log(drr);// </script>
</body>
</html>
边栏推荐
- The txt file named according to the sequence number is renamed from the back to the front
- 解决5G使用痛点,魅族17 mSmart 5G快省稳技术发布
- TCP的粘包拆包问题+解决方案
- 台积电3nm细节曝光:晶体管密度高达2.5亿个/mm²,性能及能效大幅提升
- [December Haikou] the 6th International Conference on ships, marine and Maritime Engineering in 2022 (naome 2022)
- Zabbix4.0使用SNMP代理方式监控vcenter6.5
- JUC工具包学习
- 消息队列常见的几种使用场景介绍
- Features of hardwired controller:
- This is the most concise guide to tcpdump in history. It's enough to read this one
猜你喜欢

Interviewer: let's talk about the specific process of network data transmission

File&递归14.1

29. Learn the stacked column chart of highcharts using percentage

Sudden, wechat important notice

Lua basic grammar learning

My annual salary is 1million, and I don't have clothes more than 100 yuan all over my body: saving money is the top self-discipline

proteus仿真arduino中调用DHT11/22温湿度传感器

C # delegate usage -- console project, which implements events through delegation

【JS 逆向百例】某公共资源交易网,公告 URL 参数逆向分析

org.junit.runners.model. InvalidTestClassError: Invalid test class ‘com.zhj.esdemo. MysqlTests‘: 1.
随机推荐
Elk log analysis system installation and deployment
Sudden, wechat important notice
Bank marketing predicts the success rate of a customer's purchase of financial products
Redis hash underlying data structure
JUC工具包学习
[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters
The share price soared 180.46%! Shanghai silicon industry, the leader of domestic large silicon wafers, is listed: the cumulative net profit in recent four years is less than 60million
Shuffle, partition and read of tfrecord
Realization of gobang man-machine combat
Redis distributed lock
Flutter pull_ to_ refresh-1.6.0/lib/src/internals/slivers. dart:164:13: Error: Method not found: ‘descr
76000 people shut down! Toshiba announced the closure of all factories in Japan
进制转换方法
JUC toolkit learning
J9数字科普:Sui网络的双共识是如何工作的?
详解分布式系统的幂等
远程调试 idea配置remote debug、在远程服务器的程序中,添加JVM启动参数-Xdebug
File & recursion 14.1
三次握手的Socket交互流程
Redis 哈希Hash底层数据结构