VDL Plugin SDK

takeRight

Import from @varavel/vdl-plugin-sdk/utils/arrays.

function takeRight<T>(arr, count): T[];

Returns a new array containing the last count elements from the input array arr. If count is greater than the length of arr, the entire array is returned.

Type Parameters

Type ParameterDescription
TThe type of elements in the array.

Parameters

ParameterTypeDescription
arrreadonly T[]The array to take elements from.
countnumberThe number of elements to take.

Returns

T[]

A new array containing the last count elements from arr.

Examples

// Returns [4, 5]
takeRight([1, 2, 3, 4, 5], 2);
// Returns ['b', 'c']
takeRight(['a', 'b', 'c'], 2);
// Returns [1, 2, 3]
takeRight([1, 2, 3], 5);