# 1. 版本号比较 localeCompare
返回一个数字来指示一个参考字符串是否在排序顺序前面或之后或与给定字符串相同。
- 返回值:
当引用字符串在比较字符串前面时返回 -1
当引用字符串在比较字符串后面时返回 1
相同位置时返回 0
'abcdefg'.localeCompare('absolute'); // -1
'1.0.1'.localeCompare('1.0.0'); // 1
'1.1.2'.localeCompare('1.2.0'); // -1
'1.1.0'.localeCompare('1.1.0'); // 0
# 2. 获取数组的最后一项 Array.at
接收一个整数值并返回该索引的项目,允许正数和负数。负整数从数组中的最后一个项目开始倒数;
返回值:匹配给定索引的数组中的元素,找不到则返回undefined;
const arr = [5, 12, 8, 130, 44]
console.log(`Using an index of ${2} the item returned is ${arr.at(2)}`) // 8
// expected output: "Using an index of 2 the item returned is 8"
console.log(`Using an index of ${-2} item returned is ${arr.at(-2)}`) // 130
// expected output: "Using an index of -2 item returned is 130"
← 1. 新特性