ES2023 Array new features All In One
ES2023 Array new features All In One
change Array by copy
Array.toReversed()
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const reversed = numbers.toReversed();
console.log("reversed =", reversed);
// reversed = [9, 8, 7, 6, 5, 4, 3, 2, 1]
console.log("original =", numbers);
// original = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Array.toSorted()
const numbers = [9, 5, 4, 3, 2, 8, 7, 6, 1];
const sortedArr = numbers.toSorted();
console.log("sorted =", sortedArr);
// sorted = [1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log("original = ", numbers);
// original = [9, 5, 4, 3, 2, 8, 7, 6, 1];
Array.with()
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
const replaceWith = numbers.with(1, `✅`);
console.log("with =", replaceWith);
// with = [1, `✅`, 3, 4, 5, 6, 7, 8, 9]
console.log("original =", numbers);
// original = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Array.toSpliced()
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
const splicedArr = numbers.toSpliced(0, 3);
console.log("toSpliced =", splicedArr);
// toSpliced = [4, 5, 6, 7, 8, 9]
console.log("original", numbers);
// original = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Array.findLast()
const arr = [{v: 3, i: 1}, {v: 2, i: 2}, {v: 3, i: 3}, {v: 2, i: 4}];
const lastV2 = arr.findLast(obj => obj.v === 2);
console.log(`lastV2 =`, lastV2);
// lastV2 = {v: 2, i: 4}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast
extend
Array
If you extend
the built in Array
object and use map, flatMap, filter, or concat on an instance, it will return a new instance
of the same type.
If you extend
an Array
and use toSorted, toReversed, toSpliced, or with the result will be a plain Array
again.
class customArray extends Array {
//
}
const languages = new customArray("JavaScript", "TypeScript", "CoffeeScript");
const upcase = languages.map(language => language.toUpperCase());
languages;
// customArray(3) ['JavaScript', 'TypeScript', 'CoffeeScript']
upcase;
// customArray(3) ['JAVASCRIPT', 'TYPESCRIPT', 'COFFEESCRIPT']
console.log(upcase instanceof customArray);
// true
// copy ✅
const reversed = languages.toReversed();
reversed;
// (3) ['CoffeeScript', 'TypeScript', 'JavaScript']
console.log(reversed instanceof customArray);
// false
// recovery ✅
const recovery = customArray.from(reversed);
recovery;
// customArray(3) ['CoffeeScript', 'TypeScript', 'JavaScript']
console.log(recovery instanceof customArray);
// true
demos
Finished Proposals
Finished proposals are proposals that have reached
stage 4
, and are included in thelatest draft
of the specification.
https://github.com/tc39/proposals/blob/main/finished-proposals.md
Ecma TC39
https://github.com/tc39/ecma262
https://github.com/tc39/notes/tree/main/meetings
refs
https://github.com/tc39/proposal-change-array-by-copy
ECMAScript 2023 & Temporal All In One
https://www.cnblogs.com/xgqfrms/p/16927831.html
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17703785.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2022-09-14 GoPro Hero 11 Black vs DJI Osmo Action 3 All In One
2022-09-14 HTML5 input inputmode All In One
2022-09-14 WebAssembly for Game Development All In One
2022-09-14 free 3D model download website All In One
2021-09-14 多维表格 All In One
2020-09-14 css break-inside
2020-09-14 how to read the system information by using the node cli tool?