ReasonJun

javascript : ecma 2023 updates 본문

Frontend/Javasciprt

javascript : ecma 2023 updates

ReasonJun 2023. 6. 8. 18:02
728x90

toReserved / toSorted / toSpliced (copy, no mutate)

const x = [1, 2, 3];
const y = x.toReversed();
y.push(0)

const arr = [1,3,2];
const sorted = arr.toSorted();
console.log(arr); // [1, 3, 2]
console.log(sorted); // [1, 2, 3]

const a = [ "a", "b", "c", "d"]
const newArray = a.toSpliced(1,2) // ['a', 'b']

with

const x = ["a", "b", "c", "x"]
x[3] = "d"
console.log(x) // ["a", "b", "c", "d"]

const x = ["a", "b", "c", "x"]
const z = x.with(3, "d"); => copy

findLast / findLastIndex

const fruit = ["🍎", "🍊", "🍓", "🍉", "🍓"]
fruit.findLast(item => item === "🍓") // "🍓"
fruit.findLastIndex(item => item === "🍓") // 4

https://www.youtube.com/watch?v=e6WV_DXGwSg

 

728x90
Comments