botbook/node_modules/@sagold/json-pointer/lib/removeUndefinedItems.ts
Rodrigo Rodriguez 6ae15fe3e5 Updated.
2024-09-04 13:13:15 -03:00

17 lines
387 B
TypeScript

/**
* Removes all `undefined` values within an array without creating additional
* arrays
*/
export function removeUndefinedItems<T = any>(array: Array<T>): Array<T> {
let i = 0;
let skip = 0;
while (i + skip < array.length) {
if (array[i + skip] === undefined) {
skip += 1;
}
array[i] = array[i + skip];
i += 1;
}
array.length = array.length - skip;
return array;
}