getOrMakeArray
getOrMakeArray<
T
>(value
):T
[]
Normalize a value into an array.
- If the input is
null
orundefined
, returns an empty array. - If the input is already an array, returns it unchanged.
- Otherwise, returns a new array containing the input as its sole element.
Type Parameters
Section titled “Type Parameters”T
The type of the input value.
Parameters
Section titled “Parameters”The value to normalize.
undefined
| null
| T
| T
[]
Returns
Section titled “Returns”T
[]
An array representation of the input value.
Example
Section titled “Example”getOrMakeArray(5); // [5]getOrMakeArray([1, 2]); // [1, 2]getOrMakeArray(null); // []getOrMakeArray(undefined); // []