30 lines
1.0 KiB
JavaScript
Raw Normal View History

2026-05-31 13:21:13 +02:00
import { without as without$1 } from "../../array/without.mjs";
import { isArrayLikeObject } from "../predicate/isArrayLikeObject.mjs";
//#region src/compat/array/without.ts
/**
* Creates an array that excludes all specified values.
*
* It correctly excludes `NaN`, as it compares values using [SameValueZero](https://tc39.es/ecma262/multipage/abstract-operations.html#sec-samevaluezero).
*
* @template T The type of elements in the array.
* @param {ArrayLike<T> | null | undefined} array - The array to filter.
* @param {...T[]} values - The values to exclude.
* @returns {T[]} A new array without the specified values.
*
* @example
* // Removes the specified values from the array
* without([1, 2, 3, 4, 5], 2, 4);
* // Returns: [1, 3, 5]
*
* @example
* // Removes specified string values from the array
* without(['a', 'b', 'c', 'a'], 'a');
* // Returns: ['b', 'c']
*/
function without(array, ...values) {
if (!isArrayLikeObject(array)) return [];
return without$1(Array.from(array), ...values);
}
//#endregion
export { without };