Returns the array.map() output, or a value if array is not an array or empty.
array
mapWithEmptyFallback([1,2,3], v => v+2, 100); // Yields: [3,4,5]mapWithEmptyFallback([], v=>v+2, 100); // Yields: [100]mapWithEmptyFallback({}, v=>v+2, [100]); // Yields: [100] Copy
mapWithEmptyFallback([1,2,3], v => v+2, 100); // Yields: [3,4,5]mapWithEmptyFallback([], v=>v+2, 100); // Yields: [100]mapWithEmptyFallback({}, v=>v+2, [100]); // Yields: [100]
If the fallback value is an array, it is returned as an array if needed. If it's a single value, it is wrapped as an array.
Array of values
Function to use for mapping values
Fallback single value or array of values
Returns the array.map() output, or a value if
array
is not an array or empty.If the fallback value is an array, it is returned as an array if needed. If it's a single value, it is wrapped as an array.