Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@writetome51/get-array-copy

writetome514MIT2.0.0TypeScript support: included

Returns independent copy of a passed array

array, manipulation, return, data, copy

readme

getArrayCopy<T>(array: T[]): T[]

Returns an identical but independent copy of array, not referencing the original.

Example

let arr = [1,2,3,4,5];  
let copy = getArrayCopy(arr);  
copy.push(10); // copy === [1,2,3,4,5,10]

// But the original hasn't changed:
console.log(arr);
// [1,2,3,4,5]

Installation

npm i @writetome51/get-array-copy

Loading

import {getArrayCopy} from '@writetome51/get-array-copy';