{"id":13526983,"url":"https://github.com/tc39/proposal-change-array-by-copy","last_synced_at":"2025-04-01T09:30:54.981Z","repository":{"id":38083563,"uuid":"351157915","full_name":"tc39/proposal-change-array-by-copy","owner":"tc39","description":"Provides additional methods on Array.prototype and TypedArray.prototype to enable changes on the array by returning a new copy of it with the change.","archived":true,"fork":false,"pushed_at":"2023-08-01T08:30:33.000Z","size":316,"stargazers_count":511,"open_issues_count":5,"forks_count":23,"subscribers_count":26,"default_branch":"main","last_synced_at":"2024-08-02T06:23:31.865Z","etag":null,"topics":["array","javascript","tc39","tuple","typedarray"],"latest_commit_sha":null,"homepage":"https://tc39.es/proposal-change-array-by-copy/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tc39.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-03-24T16:55:57.000Z","updated_at":"2024-07-23T00:51:21.000Z","dependencies_parsed_at":"2023-01-24T22:16:19.532Z","dependency_job_id":"9eeaac60-0491-48a6-9565-d71eac63642c","html_url":"https://github.com/tc39/proposal-change-array-by-copy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-change-array-by-copy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-change-array-by-copy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-change-array-by-copy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-change-array-by-copy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tc39","download_url":"https://codeload.github.com/tc39/proposal-change-array-by-copy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222715346,"owners_count":17027693,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","javascript","tc39","tuple","typedarray"],"created_at":"2024-08-01T06:01:38.814Z","updated_at":"2024-11-02T12:30:19.055Z","avatar_url":"https://github.com/tc39.png","language":"HTML","funding_links":[],"categories":["HTML"],"sub_categories":[],"readme":"\u003e **Note**\r\n\u003e This proposal is ['finished'](https://github.com/tc39/proposals/blob/main/finished-proposals.md) and has been merged into the ECMAScript spec. [PR](https://github.com/tc39/ecma262/pull/2997)\r\n\r\n# Change Array by copy\r\n\r\nProvides additional methods on `Array.prototype` and `TypedArray.prototype` to enable changes on the array by returning a new copy of it with the change.\r\n\r\n## Status\r\n\r\nThis proposal is currently at [Stage 4].\r\n\r\n- [Candidate spec text][spec]\r\n\r\n[Stage 4]: https://github.com/tc39/proposals/commit/ad4df8435f27f39eda26db3b940ae151980c8015#diff-af1d66eb7dbbf6f66e871d26bcad07076a557256a957f558ca21e60924e2b0b7\r\n[spec]: https://github.com/tc39/ecma262/pull/2997/files\r\n\r\n## Champions\r\n\r\n- Robin Ricard (Bloomberg)\r\n- Ashley Claymore (Bloomberg)\r\n\r\n## Reviewers\r\n\r\n- [Jordan Harband](https://github.com/ljharb)\r\n- [Justin Ridgewell](https://github.com/jridgewell)\r\n- [Sergey Rubanov](https://github.com/chicoxyzzy)\r\n\r\n## Overview\r\n\r\nThis proposal introduces the following function properties to `Array.prototype`:\r\n\r\n- `Array.prototype.toReversed() -\u003e Array`\r\n- `Array.prototype.toSorted(compareFn) -\u003e Array`\r\n- `Array.prototype.toSpliced(start, deleteCount, ...items) -\u003e Array`\r\n- `Array.prototype.with(index, value) -\u003e Array`\r\n\r\nAll of those methods keep the target Array untouched and returns a copy of it with the change performed instead.\r\n\r\n`toReversed`, `toSorted`, and `with` will also be added to TypedArrays:\r\n\r\n- `TypedArray.prototype.toReversed() -\u003e TypedArray`\r\n- `TypedArray.prototype.toSorted(compareFn) -\u003e TypedArray`\r\n- `TypedArray.prototype.with(index, value) -\u003e TypedArray`\r\n\r\nThese methods will then be available on subclasses of `TypedArray`. i.e. the following:\r\n\r\n- `Int8Array`\r\n- `Uint8Array`\r\n- `Uint8ClampedArray`\r\n- `Int16Array`\r\n- `Uint16Array`\r\n- `Int32Array`\r\n- `Uint32Array`\r\n- `Float32Array`\r\n- `Float64Array`\r\n- `BigInt64Array`\r\n- `BigUint64Array`\r\n\r\n### Example\r\n\r\n```js\r\nconst sequence = [1, 2, 3];\r\nsequence.toReversed(); // =\u003e [3, 2, 1]\r\nsequence; // =\u003e [1, 2, 3]\r\n\r\nconst outOfOrder = new Uint8Array([3, 1, 2]);\r\noutOfOrder.toSorted(); // =\u003e Uint8Array [1, 2, 3]\r\noutOfOrder; // =\u003e Uint8Array [3, 1, 2]\r\n\r\nconst correctionNeeded = [1, 1, 3];\r\ncorrectionNeeded.with(1, 2); // =\u003e [1, 2, 3]\r\ncorrectionNeeded; // =\u003e [1, 1, 3]\r\n```\r\n\r\n## Motivation\r\n\r\nThe [`Tuple.prototype`][tuple-proto] introduces these functions as a way to deal with the immutable aspect of the Tuples in [Record \u0026 Tuple][r-t]. While Arrays are not immutable by nature, this style of programming can be beneficial to users dealing with frozen arrays for instance.\r\n\r\nThis proposal notably makes it easier to write code able to deal with Arrays and Tuples interchangeably.\r\n\r\n## Relationship with [Record \u0026 Tuple][r-t]\r\n\r\nWhile this proposal is derived from [Record \u0026 Tuple][r-t], it should progress independently.\r\n\r\nIf web compatibility prescribes it, property names defined in this proposal are going to be changed. Those changes should be reflected on [`Tuple.prototype`][tuple-proto].\r\n\r\n[tuple-proto]: https://tc39.es/proposal-record-tuple/#sec-properties-of-the-tuple-prototype-object\r\n[r-t]: https://github.com/tc39/proposal-record-tuple\r\n\r\n## Implementations\r\n\r\n - [Firefox/SpiderMonkey](https://bugzilla.mozilla.org/show_bug.cgi?id=1729563), shipping unflagged since [Firefox 115](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/115)\r\n - [Safari/JavaScriptCore](https://bugs.webkit.org/show_bug.cgi?id=234604), shipping unflagged since [Safari Tech Preview 146](https://developer.apple.com/safari/technology-preview/release-notes/#:~:text=bug%20tracker.-,Release%20146,-Note%3A%20Tab)\r\n - [Chrome/V8](https://bugs.chromium.org/p/v8/issues/detail?id=12764), shipping unflagged since Chrome 110\r\n\r\n - [Ladybird/LibJS](https://github.com/SerenityOS/serenity/issues/16353), shipping unflagged\r\n\r\n - [core-js](https://github.com/zloirock/core-js)\r\n   - [change-array-by-copy](https://github.com/zloirock/core-js#change-array-by-copy)\r\n\r\n - [es-shims](https://github.com/es-shims):\r\n   - [`array.prototype.tosorted`](https://www.npmjs.com/package/array.prototype.tosorted)\r\n   - [`array.prototype.toreversed`](https://www.npmjs.com/package/array.prototype.toreversed)\r\n   - [`array.prototype.tospliced`](https://www.npmjs.com/package/array.prototype.tospliced)\r\n   - [`array.prototype.with`](https://www.npmjs.com/package/array.prototype.with)\r\n\r\n- [./polyfill.js](./polyfill.js) (minimalist reference implementation)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftc39%2Fproposal-change-array-by-copy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftc39%2Fproposal-change-array-by-copy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftc39%2Fproposal-change-array-by-copy/lists"}