Skip to content

ECMAScript2023数组新方法

ECMAScript 2023 Array对象新增了toSortedtoReversedwithfindLastfindLastIndex等方法。由于目前工程中使用的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