Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECMAScript 2023的特性 #20

Open
yayxs opened this issue Oct 17, 2023 · 0 comments
Open

ECMAScript 2023的特性 #20

yayxs opened this issue Oct 17, 2023 · 0 comments
Labels
ECMAScript This issue or pull request already exists

Comments

@yayxs
Copy link
Owner

yayxs commented Oct 17, 2023

/**
 * 从数组的末尾开始搜索数组
 *
 * @since 2023
 * @see
 * @example
 */

const array = [{ v: 2023 }, { v: 2022 }]

console.log(array.findLast((ele) => ele.v === 2022)) // { v: 2023 }
console.log(array.findLastIndex((ele) => ele.v > 2023)) // -1

/**
 * 非破坏性的 反转旧数组
 *
 * @since 2023
 * @see
 * @example
 *
 * //
 */

const oldArray = ['1', '2', '3']
const newArray = oldArray.toReversed()

console.log('oldArray', oldArray)
console.log('newArray', newArray)

/**
 * 非破坏性的 排序数组
 *
 * @since 2023
 * @see
 * @example
 *
 */

const oldArray1 = ['3', '2', '1']
const newArray1 = oldArray1.toSorted()

console.log('oldArray', oldArray1) // ['3', '2', '1']
console.log('newArray', newArray1) // ['1', '2', '3']

/**
 * 非破坏性的
 *
 * @since 2023
 * @see
 * @example
 *
 */

const oldArray2 = ['1', '2', '3']
const newArray2 = oldArray1.toSpliced(1, 2, 'x')
console.log(oldArray2)
console.log(newArray2)

/**
 * with
 *
 * @since 2023
 * @see
 * @example
 *
 */

const oldArray3 = ['1', '2', '3']
const newArray3 = oldArray3.with(1, 'X')

console.log(oldArray3) // ['1', '2', '3']
console.log(newArray3) // ['1', 'X', '3']

/**
 * weakmap
 *
 * @since 2023
 * @see
 * @example
 *
 */

const wm = new WeakMap()

// Symbol 的 key
const key = Symbol('sym-key')
const object = {}
wm.set(key, object)
@yayxs yayxs added the ECMAScript This issue or pull request already exists label Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ECMAScript This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

1 participant