Closed6

ES2023に入りそうな機能

Sosuke SuzukiSosuke Suzuki

findILast / findLastIndex

https://github.com/tc39/proposal-array-find-from-last

Array.prototype.findArray.prototype.findIndex の、後ろから走査する版。

const array = [{ value: 1 }, { value: 2 }, { value: 3 }, { value: 4 }];

array.find(n => n.value % 2 === 1); // { value: 1 }
array.findIndex(n => n.value % 2 === 1); // 0

array.findLastIndex(n => n.value % 2 === 1); // 2
array.findLastIndex(n => n.value === 42); // -1
Sosuke SuzukiSosuke Suzuki

Change array by copy

https://github.com/tc39/proposal-change-array-by-copy

今までの ECMAScript の Array.prototype に実装されているメソッドの多くは、レシーバの配列を破壊するものでした。このプロポーザルは、破壊せずにコピーして返すメソッドを導入します。

const sequence = [1, 2, 3];
sequence.toReversed(); // => [3, 2, 1]
sequence; // => [1, 2, 3]

const outOfOrder = new Uint8Array([3, 1, 2]);
outOfOrder.toSorted(); // => Uint8Array [1, 2, 3]
outOfOrder; // => Uint8Array [3, 1, 2]

const correctionNeeded = [1, 1, 3];
correctionNeeded.with(1, 2); // => [1, 2, 3]
correctionNeeded; // => [1, 1, 3]
このスクラップは2023/05/17にクローズされました