tsdotnet / array-copy
A commonly used array copy utility.
Usage
import arrayCopy, {arrayCopyTo} from '@tsdotnet/array-copy'
const myCopy = arrayCopy(source);
const myOtherCopy = arrayCopyTo([]);
or
import arrayCopy from '@tsdotnet/array-copy'
const myOtherCopy = arrayCopy.to([]);
Exported
For flexibility, these functions can operate on objects that have a length but are not instances of Array. (ArrayLikeWritable<T>
)
arrayCopyTo
export function arrayCopyTo<T, TDestination extends ArrayLikeWritable<T>> (
source: ArrayLike<T>,
destination: TDestination,
sourceIndex: number = 0,
destinationIndex: number = 0,
count: number = Infinity
): TDestination
arrayCopy
export default function arrayCopy<T> (
source: ArrayLike<T>,
sourceIndex: number = 0,
count: number = Infinity
): T[]