Get a subarray view of the first n elements of an array-like object, to use with constructing a new one, with minimal allocaitons.
n
The type of the array-like object
The array-like object to take elements from
The maximum number of elements to take. If
An array-like object whose length property is guaranteed to be <= n
length
This is primarily useful for setting elements of a TypedArray using its set method.
TypedArray
set
const arr = new Uint8Array(3);const other = [1, 2, 3, 4, 5];// Using arr.set(other) would throw, as other.length > arr.lengtharr.set(subArray(other, arr.length));@throws {TypeError}If `arr` is not an array or typed array (though typescript should prevent this Copy
const arr = new Uint8Array(3);const other = [1, 2, 3, 4, 5];// Using arr.set(other) would throw, as other.length > arr.lengtharr.set(subArray(other, arr.length));@throws {TypeError}If `arr` is not an array or typed array (though typescript should prevent this
Get a subarray view of the first
n
elements of an array-like object, to use with constructing a new one, with minimal allocaitons.