当前位置:网站首页>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>
边栏推荐
- org.junit.runners.model.InvalidTestClassError: Invalid test class ‘com.zhj.esdemo.MysqlTests‘: 1.
- 一加将在2020年释放ODM订单,发力中低端市场
- Binary conversion method
- urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: un
- reduce错误示范
- [ACTF新生赛2020]crypto-aes
- Accelerate IGBT localization! BYD semiconductor will be listed independently, with a market value of 30billion yuan!
- 尚硅谷尚品项目汇笔记(一)
- How to use xshell Free Edition
- Bank marketing predicts the success rate of a customer's purchase of financial products
猜你喜欢

QT with OpenGL(Shadow Mapping)(平行光篇)

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

Application of user portrait in precise push of wechat official account of scientific journals

字符流学习14.3

详解分布式系统的幂等

Key points of data management

NDK series (6): let's talk about the way and time to register JNI functions

Spark 离线开发框架设计与实现

Redis 哈希Hash底层数据结构

The technology of applet container is very promising, which can greatly improve the efficiency of mobile R & D
随机推荐
Unity 实现简单画板画画功能(笔记)
2022/7/24-7/25
数据中台的那些“经验与陷阱”
Arm32 for remote debugging
CPU的控制方式
编辑复制粘贴判定问题(bug?),所见即所得显示符号问题反馈。
7.6万人停工!东芝宣布关闭日本所有工厂
File & recursion 14.1
JS array copy speed test 220320
[GWCTF 2019]BabyRSA1
TOGAF10标准读书会首场活动圆满举办,精彩时刻回顾!
基于原生js实现今日新闻网站
五子棋人机对战实现
为什么需要等待计时2MSL?
消息队列常见的几种使用场景介绍
Smartrefresh nested multiple recycleview sliding conflicts and incomplete layout display
76000 people shut down! Toshiba announced the closure of all factories in Japan
采用汇顶屏下光学指纹方案,三星Galaxy A71 5G上市
面试官问线程安全的List,看完再也不怕了!
技术认证 | 图扑软件携手华为云再创合作共赢新局面