Deprecated: Typecho\Widget\Request::getServer(): Implicitly marking parameter $default as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Widget\Request.php on line 219

Deprecated: Typecho\Request::getServer(): Implicitly marking parameter $default as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Request.php on line 349

Deprecated: Typecho\Widget\Response::goBack(): Implicitly marking parameter $suffix as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Widget\Response.php on line 158

Deprecated: Typecho\Widget\Response::goBack(): Implicitly marking parameter $default as nullable is deprecated, the explicit nullable type must be used instead in D:\PHP_HOME\www\gp_blog\var\Typecho\Widget\Response.php on line 158
标签 sort 下的文章 - 开发者
Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in D:\PHP_HOME\www\gp_blog\var\Widget\Archive.php on line 1057

标签 sort 下的文章

相信大家对数组排序都不陌生,在开发中我们通常会使用sort方法进行数组的排序。今天我主要带大家回顾一下JS中几种常用的数组排序方式。

1. sort方法
基本思路:
sort方法默认按照字符的ASCII码进行升序排序。可以传一个函数作为参数并返回一个数值实现升序或降序排列。
代码实现:

var arr = [18, 2, 10, 9, 88, 66, 22];
arr.sort(function (a, b) {
return b - a; //降序排序
// return a - b; //升序排序
});
console.log(arr); //[88,66,22,18,10,9,2]

- 阅读剩余部分 -