Appearance
ECMAScript2023数组新方法
ECMAScript 2023 Array
对象新增了toSorted
、toReversed
、with
、findLast
、findLastIndex
等方法。由于目前工程中使用的core-js库
版本为3.14.0,暂不支持转译Array
对象新增的方法,所以需要使用lodash库
中的方法来进行替换。
- 部分方法示例。
javascript
_.last([1, 2, 3]);
// => 3
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': false }
];
_.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
// => 2