util-ex
Version:
Browser-friendly enhanced util fully compatible with standard node.js
15 lines (14 loc) • 350 B
JavaScript
import isArray from "../is/type/array.mjs";
export function filterNullUndefined(obj) {
if (isArray(obj)) {
return obj.filter(item => item != null)
} else if (obj) {
return Object.keys(obj).reduce((acc, key) => {
const value = obj[key];
if (value != null) {
acc[key] = value;
}
return acc;
}, {})
}
}